gpt4 book ai didi

python - RobotFramework - 如何从关键字返回值并停止?

转载 作者:行者123 更新时间:2023-12-03 00:13:38 24 4
gpt4 key购买 nike

我想从关键字和 exit 关键字返回一个值,就像在编程语言中从函数返回值时所做的那样。该关键字从页面上的列表中选择一个随机项目,但如果页面仅包含 1 个项目,那么整个事情就会崩溃。我无法找到解决方案,这就是我在 atm 上所做的:

Get Random Item From Page
# Pass the general list items xpath to the argument
[Arguments] ${element_path}
${elements}= Get Element Count ${element_path}
Run Keyword If ${elements} == 1 [Return] ${element_path}[1]
${random}= FakerLibrary.Random Int 1 ${elements}
[Return] ${element_path}[${random}]

问题在于它继续执行第一个返回标记之后的关键字。我做错了什么?

最佳答案

您可以使用Return from keywordReturn from keyword if从关键字中间返回。

示例

*** Keywords ***
Is number even or odd?
[Arguments] ${number}
log number is ${number}
Return from keyword if int('${number}')%2 == 0 even
Return from keyword odd

*** Test cases ***
Test even number
${result}= Is number even or odd? 4
should be equal ${result} even

Test odd number
${result}= Is number even or odd? 5
should be equal ${result} odd

关于python - RobotFramework - 如何从关键字返回值并停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49051972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com