简体   繁体   English

将变量从 python 文件传递​​给机器人框架变量

[英]Pass variables from python file to robot framework variables

I am assigning variables in robot framework as我在机器人框架中分配变量为

*** Variables ***
${TestNAME}                       test

But can I pass variable value from python file?但是我可以从 python 文件传递​​变量值吗?

#test.py
var = 'test'

Is it possible to assign var to ${TESTNAME} ?是否可以将var分配给${TESTNAME}

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.如果您有一个名为“test.py”的文件,其中定义了变量,则可以使用机器人变量文件功能导入变量。

Here's an example, using the pipe-separated format for clarity:这是一个示例,为了清楚起见,使用管道分隔格式:

*** Settings ***
| Variables | test.py

*** Variables ***
| ${myTestName} | ${var}

This works because settings are processed before the Variables table.这是有效的,因为设置是在Variables表之前处理的。 Any variables in the python file can be referenced using the standard robot syntax for variables (eg: python variable var is referenced as ${var} )可以使用变量的标准机器人语法引用 python 文件中的任何变量(例如:python 变量var被引用为${var}

Note, however, that ${Testname} is automatically set by robot, so your exact requirement can't be met.但是请注意, ${Testname}是由机器人自动设置的,因此无法满足您的确切要求。 If you use a non-automatic variable, you can set it the way you want, which is why the above example used ${myTestName} .如果您使用非自动变量,您可以按照您想要的方式设置它,这就是上面示例使用${myTestName}

eg:- The variable file is as shown - var.py例如:- 变量文件如图所示- var.py

x = 10 x = 10

y = 20 y = 20

file1.robot can be written as shown:- file1.robot 可以这样写:-

*** Settings *** *** 设置 ***

Variables var.py变量 var.py

*** Test Cases *** *** 测试用例 ***

KEYW1 KEYW1

  Log  ${x}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM