简体   繁体   中英

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?

#test.py
var = 'test'

Is it possible to assign var to ${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.

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. Any variables in the python file can be referenced using the standard robot syntax for variables (eg: python variable var is referenced as ${var} )

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} .

eg:- The variable file is as shown - var.py

x = 10

y = 20

file1.robot can be written as shown:-

*** Settings ***

Variables var.py

*** Test Cases ***

KEYW1

  Log  ${x}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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