机器人框架设置套件变量

时间:2017-07-31 08:07:05

标签: robotframework

在Robot框架脚本中,我试图选择各个套件使用的通信协议(telnet或ssh)。我已经尝试了下面描述的实现,但它不起作用。

有人可以提供帮助,或者分享更好的实施建议吗?

*** Settings ***
Suite Setup       Custom Suite Setup
Library           ${suiteCommProtocol}

*** Keywords ***
Custom Suite Setup
    ${suiteCommProtocol} =    Set Variable    Telnet
    Set Global Variable    ${suiteCommProtocol}    Telnet

2 个答案:

答案 0 :(得分:0)

导入在任何关键字运行之前发生,因此根据关键字创建的变量在设置表中使用变量是不可能的。

如果要在运行时加载库,请使用内置关键字import library

*** Keywords ***
Custom Suite Setup
    ${suiteCommProtocol} =    Set Variable    Telnet
    Set Global Variable    ${suiteCommProtocol}    Telnet
    import library    ${suiteCommProtocol}

答案 1 :(得分:0)

要添加@Bryan Oakley的答案,更好的实现可能是创建带有Variables部分的Resource文件并将变量设置为Telnet,然后使用Custom Suite Setup关键字中的变量。

*** Variables ***
${suiteComm}    Telnet

*** Keywords ***
Custom Suite Setup
    ${suiteCommProtocol} =  Set Variable    ${suiteComm}
    Set Global Variable     ${suiteCommProtocol}    ${suiteComm}
    Import Library  ${suiteCommProtocol}

这样,您只需更改资源文件顶部的一个变量即可在Telnet和ssh之间切换。我并不是要声明他的代码究竟在做什么,但我知道如何确保你可以用一个变量来改变一切。