Robotframework 在Robot框架中将变元作为返回值处理
在经过一些操作后返回参数变量时,我遇到了一个问题 请看代码:注意这是一个示例代码Robotframework 在Robot框架中将变元作为返回值处理,robotframework,Robotframework,在经过一些操作后返回参数变量时,我遇到了一个问题 请看代码:注意这是一个示例代码 *** Settings *** Library Selenium2Library Library Collections *** Keywords *** Parent Routine ${index} Set Variable 0 ${index} Set Variable Child Routine ${index} log to co
*** Settings ***
Library Selenium2Library
Library Collections
*** Keywords ***
Parent Routine
${index} Set Variable 0
${index} Set Variable Child Routine ${index}
log to console ${index}
Child Routine
[Arguments] ${index}
${index} Set Variable Grand Child Routine ${index}
#\ Some other manipulation
[Return] ${index}
Grand Child Routine
[Arguments] ${index}
: For ${i} IN RANGE 1 5
\ ${index} Set Variable ${index} + 1
#\ Some other manipulation
[Return] ${index}
*** Test Cases ***
Sample Test Case
[Documentation] Simple test for Return Value
Parent Routine
请查看输出窗口
最可能的预期输出是5,但它显示[u'Child Routine',u'0']
请帮助我如何获得预期的输出。是的,我们可以使用
在代码中,缺少Evaluate关键字。在进行任何数学运算之前,我们应该使用Evaluate关键字
唯一的更改是${index}=Evaluate${index}+1
最后,您的代码是
*** Settings ***
Library Selenium2Library
Library Collections
*** Keywords ***
Parent Routine
${index} Set Variable 0
${index} Set Variable Child Routine ${index}
log to console ${index}
Child Routine
[Arguments] ${index}
${index} Set Variable Grand Child Routine ${index}
#\ Some other manipulation
[Return] ${index}
Grand Child Routine
[Arguments] ${index}
: For ${i} IN RANGE 1 5
\ ${index}= Evaluate ${index} + 1
#\ Some other manipulation
[Return] ${index}
*** Test Cases ***
Sample Test Case
[Documentation] Simple test for Return Value
Parent Routine
这是因为您试图通过将用户关键字传递给只接受字符串值的Set变量来调用用户关键字。当您传入多个值时,您将得到一个列表 如果要调用用户关键字并将其返回值分配给变量,则需要使用Run关键字 设置变量 你用错了。该关键字用于设置变量的值,而不是调用其他关键字 考虑以下代码:
${index} Set Variable Child Routine ${index}
您正在创建一个列表,其中第一个值是文本字符串子例程,第二个值是${index}中的任何值,然后将变量${index}设置为该列表
如果你想调用一个关键字并保存它的返回值,你所要做的就是让这个关键字成为变量之后的第一件事。例如,在下面的代码中,我们调用子例程,将${index}作为其唯一参数传递给它。结果将保存在${index}中
做数学
不能只向变量中添加+1。Robot并不完全是一种编程语言。如果你想添加一个变量,你需要使用一些关键字来完成。内置关键字可用于此类目的
换句话说,与此相反:
${index} Set Variable ${index} + 1
您需要这样做:
${index} evaluate ${index} + 1
这三个答案都是正确的,我在标记答案时感到困惑。这三个答案都是正确的,我在标记答案时感到困惑。这三个答案都是正确的,我在标记答案时感到困惑。这三个答案都是正确的,我在标记答案时感到困惑。
${index} Set Variable ${index} + 1
${index} evaluate ${index} + 1