Robotframework 机器人框架设置套件变量
在Robot框架脚本中,我试图选择通信协议(telnet或ssh)供各个套件使用。我已经尝试了下面描述的实现,但它不起作用 有人能帮忙吗,或者分享一个更好的实施方案Robotframework 机器人框架设置套件变量,robotframework,Robotframework,在Robot框架脚本中,我试图选择通信协议(telnet或ssh)供各个套件使用。我已经尝试了下面描述的实现,但它不起作用 有人能帮忙吗,或者分享一个更好的实施方案 *** Settings *** Suite Setup Custom Suite Setup Library ${suiteCommProtocol} *** Keywords *** Custom Suite Setup ${suiteCommProtocol} = Set Var
*** Settings ***
Suite Setup Custom Suite Setup
Library ${suiteCommProtocol}
*** Keywords ***
Custom Suite Setup
${suiteCommProtocol} = Set Variable Telnet
Set Global Variable ${suiteCommProtocol} Telnet
导入发生在任何关键字运行之前,因此不可能基于关键字创建的变量在设置表中使用变量 如果要在运行时加载库,请使用内置关键字
为了补充@Bryan Oakley的答案,更好的实现可能是使用Variables部分创建资源文件,并将变量设置为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之间切换。我并不完全理解他的代码在做什么,但我知道如何确保您可以用一个变量更改所有内容。“我已经尝试了下面描述的实现”-它明显不可见,因为我看不到它..?请将代码作为文本粘贴到问题中,然后突出显示并按Ctrl+K。这允许我们将代码复制并粘贴到IDE中,并帮助识别问题。请阅读以了解需要包含哪些代码。我现在修改了问题,将代码也包含在内。
*** Variables ***
${suiteComm} Telnet
*** Keywords ***
Custom Suite Setup
${suiteCommProtocol} = Set Variable ${suiteComm}
Set Global Variable ${suiteCommProtocol} ${suiteComm}
Import Library ${suiteCommProtocol}