Pass variables from python file to robot framework variables

让人想犯罪 __ 提交于 2020-01-02 05:22:07

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/34426448/pass-variables-from-python-file-to-robot-framework-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!