2017-07-31 37 views
-3

在Robot框架脚本中,我试图选择单个套件使用的通信协议(telnet或ssh)。我试过下面描述的实现,但它不起作用。机器人框架设置套件变量

有人能帮忙,还是分享一个更好的实施建议?

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

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

“我尝试过下面描述的实现” - 它显然是看不见的,因为我无法看到它..? – Goralight

+0

请将代码作为文本粘贴到您的问题中,然后突出显示并按Ctrl + K,这样我们就可以将您的代码复制并粘贴到我们的IDE中,并帮助识别问题。请阅读[如何创建一个最小,完整,可验证的示例](https://stackoverflow.com/help/mcve)知道你需要包含哪些代码 – WhatsThePoint

+0

我现在修改了问题以包含代码。 – ajs1

回答

0

进口发生任何关键字运行之前,所以这是不可能的基础上通过关键字创建一个变量设置表来使用一个变量。

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

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

要添加到@Bryan奥克利的回答,更好的实现可能是创建一个资源文件变量部分并将变量设置为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之间切换。我并没有声称完全明白他的代码在做什么,但我知道如何确保你可以用一个变量来改变所有的东西。