how to pass values from python code to variable of robot framework

可紊 提交于 2020-01-03 05:32:22

问题


I'm beginner in robot framework. I want to pass values from python file to variable of robot framework, but still can't work successfully.

globe.py is my python file and it's very simple.

a = 'this is testing'

below is test case configuration as robot required

*** Setting ***
|Variables|globe.py

*** Variables ***
|${myTest}|${a}

but robot throw error :

"Error in file: Setting variable '${myTest}' failed: Variable '${a}' not found."

could you give some suggestion on that?

here is screen about my execution steps and result


回答1:


It seems to me that your example does work. I use the tab delimited approach, but that shouldn't be the cause.

*** Setting ***
Variables   globe.py

*** Variables ***
${myTest}   ${a}

*** Test Cases ***
A Test Case
     Log To Console    ${myTest}

This resulted into this response from Robot Framework which appears to be what you're looking for.

Suite Executor: Robot Framework 3.0 (Python 2.7.9 on win32)
==============================================================================
MyLibrary                                                                     
==============================================================================
MyLibrary.Test                                                                
==============================================================================
A Test Case                                                           this is testing
| PASS |
------------------------------------------------------------------------------
MyLibrary.Test                                                        | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
MyLibrary                                                             | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================



回答2:


You can also try to import the variables .py file prior to use..

Import Library   <yourPythonFile.py>
#use variables from python variables file after successful import..



回答3:


The other workaround is using --variablefile option of robotframework.

Test_varaibles.robot

*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
  print msg
*** Keywords ***
print msg
  log to console ${msg}

Declare a variable msg in a python file

variable.py

msg='Hello!! This is First msg!'

To pass a variable file, we need to pass –variablefile or -V as a command line argument to pybot

run below command

pybot -V variable.py Test_variables.robot

Result

For more descriptive details, you can also refer below

https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/



来源:https://stackoverflow.com/questions/41787572/how-to-pass-values-from-python-code-to-variable-of-robot-framework

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