(1)如果当前作用域中已经存在一个变量,则可以将该值保留为空,而新作用域中的变量将获取当前作用域中的值。
目标是实现语句(1)的示例。
这是尝试:
(Test 1/2) Use "Set Suite Variable" : Set Locally Scoped Variable As Suite Scoped
[Documentation] If a variable already exists within the current scope
... (i.e. Test 1/2), the value can be left empty and
... the variable within the new scope (i.e. Test 2/2) gets
... the value within the current scope (i.e Test 1/2)
${local_to_suite_scoped} = Set Test Variable ${3}
# intentionally not setting any value to comply with the statement (1)
Set Suite Variable ${local_to_suite_scoped}
(Test 2/2) Use "Set Suite Variable" : Use local_to_suite_scoped in this test
Variable Should Exist ${local_to_suite_scoped}
Should Be Equal ${local_to_suite_scoped} ${3} # fails with None != 3, expected 3 == 3
测试2/2失败,但是为什么呢?陈述(1)是否正确或测试用例是否正确实施?如果测试用例的实现不正确,您能否提供正确的实现?
答案 0 :(得分:1)
Set Test Variable
(如Set Suite Variable
-keyword)期望第一个参数是变量的名称。然后,第二个变量将是变量的值。所以代替
${local_to_suite_scoped} = Set Test Variable ${3}
做
Set Test Variable ${local_to_suite_scoped} ${3}
在http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Suite%20Variable上查看更多信息