Return 来自 [setup] 关键字的值
Return a value from a keyword in [setup]
在测试用例设置中的关键字 运行 中,我有一个时间戳,稍后我必须在测试用例主体中使用它。 return 它到测试用例主体的最佳方法是什么?我只考虑过使用测试范围变量,但理想情况下希望将其作为 return 参数传递。
举例说明:
*** Keywords ***
setup keyword
${ts} = evaluate <whatever>
*** Test Cases ***
case1
[setup] setup keyword
#here I need ${ts}
您不能 return 设置中的值。您的两个选择是在设置关键字中设置测试级别变量(使用 Set test variable 关键字),或者调用设置关键字作为测试的第一步而不是设置步骤。我个人更喜欢前者。
您可以使用套件变量,因为设置对整个套件是通用的。
*** keywords ***
setup keyword
${temp} = evaluate
Set Suite Variable ${ts} ${temp}
*** Test Cases ***
case1
[setup] setup keyword
#here I need ${ts}
我在尝试将 pytest setup 和 teardown 转换为 robotframework 时遇到了类似的问题。以下是我在 pytest 中的设置和拆卸:
import pytest
@pytest.fixture()
def configuration_setup(request):
shutil.copy(config, backup)
modify(config)
def teardown():
shutil.copy(backup, config)
request.addfinalizer(teardown)
我需要 return 在执行安装过程中使用拆卸功能。
def configuration_setup():
shutil.copy(config, backup)
modify(config)
def teardown():
shutil.copy(backup, config)
return teardown
所以我最终像这样使用 Set Test Variable
:
*** Keywords ***
Create config backup
${created_backup} Configuration setup config backup
Set Test Variable ${undo_backup} ${created_backup}
然后我可以使用 return 值作为我的拆解。
*** Test Cases ***
A test case
[Setup] Create config backup
Another Keywords Arg1 Arg2
[Teardown] ${undo_backup()}
在测试用例设置中的关键字 运行 中,我有一个时间戳,稍后我必须在测试用例主体中使用它。 return 它到测试用例主体的最佳方法是什么?我只考虑过使用测试范围变量,但理想情况下希望将其作为 return 参数传递。
举例说明:
*** Keywords ***
setup keyword
${ts} = evaluate <whatever>
*** Test Cases ***
case1
[setup] setup keyword
#here I need ${ts}
您不能 return 设置中的值。您的两个选择是在设置关键字中设置测试级别变量(使用 Set test variable 关键字),或者调用设置关键字作为测试的第一步而不是设置步骤。我个人更喜欢前者。
您可以使用套件变量,因为设置对整个套件是通用的。
*** keywords *** setup keyword ${temp} = evaluate Set Suite Variable ${ts} ${temp} *** Test Cases *** case1 [setup] setup keyword #here I need ${ts}
我在尝试将 pytest setup 和 teardown 转换为 robotframework 时遇到了类似的问题。以下是我在 pytest 中的设置和拆卸:
import pytest
@pytest.fixture()
def configuration_setup(request):
shutil.copy(config, backup)
modify(config)
def teardown():
shutil.copy(backup, config)
request.addfinalizer(teardown)
我需要 return 在执行安装过程中使用拆卸功能。
def configuration_setup():
shutil.copy(config, backup)
modify(config)
def teardown():
shutil.copy(backup, config)
return teardown
所以我最终像这样使用 Set Test Variable
:
*** Keywords ***
Create config backup
${created_backup} Configuration setup config backup
Set Test Variable ${undo_backup} ${created_backup}
然后我可以使用 return 值作为我的拆解。
*** Test Cases ***
A test case
[Setup] Create config backup
Another Keywords Arg1 Arg2
[Teardown] ${undo_backup()}