从[设置]

时间:2015-06-04 05:22:27

标签: robotframework

在测试用例的设置中运行的关键字中,我有一个时间戳,我必须稍后在测试用例体中使用。将它返回测试用例体的最佳方法是什么?我只考虑使用测试范围变量,但理想情况下想将其作为返回参数传递。

举例说明:

*** Keywords ***
setup keyword
    ${ts} =    evaluate    <whatever>

*** Test Cases ***
case1
    [setup]    setup keyword
    #here I need ${ts}

3 个答案:

答案 0 :(得分:4)

您无法在设置中返回值。您有两种选择是在设置关键字中设置测试级别变量(使用Set test variable关键字),或者将您的设置关键字作为测试的第一步而不是设置步骤。我个人更喜欢前者。

答案 1 :(得分:0)

您可以使用套件变量,因为整个套件的设置是通用的。

*** keywords ***
setup keyword
    ${temp} =    evaluate    
    Set Suite Variable  ${ts}  ${temp}


*** Test Cases ***
case1
    [setup]    setup keyword
    #here I need ${ts}

答案 2 :(得分:0)

我在尝试将pytest设置和拆卸转换为机器人框架时遇到了类似的问题。以下是我在pytest中的设置和拆解:

import pytest

@pytest.fixture()
def configuration_setup(request):
    shutil.copy(config, backup)
    modify(config)

    def teardown():
        shutil.copy(backup, config)    

    request.addfinalizer(teardown)

我需要在执行安装过程中返回拆卸功能。

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}

然后我可以使用返回值作为我的拆解。

*** Test Cases ***
A test case
    [Setup]    Create config backup
    Another Keywords    Arg1    Arg2
    [Teardown]    ${undo_backup()}