将变量从 python 文件传递给机器人框架变量 [英] Pass variables from python file to robot framework variables
问题描述
我将机器人框架中的变量赋值为
I am assigning variables in robot framework as
*** Variables ***
${TestNAME} test
但是我可以从 python 文件中传递变量值吗?
But can I pass variable value from python file?
#test.py
var = 'test'
是否可以将 var
分配给 ${TESTNAME}
?
Is it possible to assign var
to ${TESTNAME}
?
推荐答案
如果您有一个名为test.py"的文件,其中定义了变量,您可以使用机器人变量文件 功能.
If you have a file named "test.py" that has variables defined in it, you can import the variables using the robot variable file feature.
这是一个示例,为了清楚起见,使用竖线分隔格式:
Here's an example, using the pipe-separated format for clarity:
*** Settings ***
| Variables | test.py
*** Variables ***
| ${myTestName} | ${var}
这是有效的,因为设置是在 Variables
表之前处理的.可以使用变量的标准机器人语法引用 python 文件中的任何变量(例如:python 变量 var
被引用为 ${var}
)
This works because settings are processed before the Variables
table. Any variables in the python file can be referenced using the standard robot syntax for variables (eg: python variable var
is referenced as ${var}
)
但是请注意,${Testname}
是 由机器人自动设置,因此无法满足您的确切要求.如果您使用非自动变量,您可以按照您想要的方式设置它,这就是为什么上面的示例使用 ${myTestName}
.
Note, however, that ${Testname}
is automatically set by robot, so your exact requirement can't be met. If you use a non-automatic variable, you can set it the way you want, which is why the above example used ${myTestName}
.
这篇关于将变量从 python 文件传递给机器人框架变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!