2017-04-17 23 views
0

我目前有一系列功能测试,我希望能够在运行时声明2个选项中的一个。测试目前正在使用XVFB并且无法正常运行。你可以在运行时用Robot Framework声明变量

操作该浏览器当前的代码是:

Start Virtual Display and enter the URL 
    [Documentation] Test creates virtual display using XVFB 
    [Arguments] ${URL} 
    start virtual display 1440 900 
    Open Browser ${URL} 
    set window size 1440 900 
    sleep ${delay} 

如果我注释掉start virtual display 1440 900一步,测试用例会自动调用本机浏览器中执行的测试步骤。

我希望有一个“简单的方法”来评论或取消注释start virtual display测试步骤 - 也许通过声明它作为一个变量?

回答

2

你可以在命令行设置变量:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#setting-variables-in-command-line

是不是还不够吗?

编辑根据您的代码示例:

Start Virtual Display and enter the URL 
    [Documentation] Test creates virtual display using XVFB 
    [Arguments] ${URL} 
    Run Keyword If '${vd}' == 'TRUE' Start Virtual Display 1440 900 
    Open Browser ${URL} 
    Set Window Size 1440 900 
    Sleep ${delay} 

然后用--variable vd:TRUE

+0

对不起 - 我没有做好描述我的实际情况 - 将修改我原来的问题澄清。 –

+0

答案扩展。 –

+0

谢谢Jan!这正是我期望做的,但现在唯一剩下的问题是现在要通过在Jenkins中运行的bash脚本来传递该变量。 –

0

打电话给你测试,在更新后的问题,在我看来,你正在寻找Run Keyword If功能,让您使用在启动RF以确定脚本执行时在命令行中指定的变量的值。更多关于运行关键字如果可以发现here