Pass variables from python file to robot framework variables

6,694 views
Skip to first unread message

bleedBlue

unread,
Dec 22, 2015, 7:01:52 PM12/22/15
to robotframework-users

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

pra...@datatorrent.com

unread,
Dec 22, 2015, 11:38:25 PM12/22/15
to robotframework-users
Yes, you can very well do that. You need to say:

*** Variables ***
$
{TestNAME}                       ${var}

in  the robot testcases file. And need to pass the variables file on commandline as:

pybot -V /path/to/variables.py testcases.txt

Or, instead of passing the variables file on commandline as argument to pybot, you can import the variables file and use the variable same way:

*** Settings ***
Variables         /path/to/variables.py


Tamali Basu

unread,
Jun 15, 2017, 5:27:31 AM6/15/17
to robotframework-users
This solution is not working for me.
I am trying to do below:
*** Settings ***
Library Selenium2Library
Variables ../Resources/RandomNum.py

*** Variables ***
${FIRSTNAME} = {firstname}
${LASTNAME} = {lastname}
${EMAILID} = {email}

Where {firstname}, {lastname} and {email} are coming from RandomNum.py file

Please help.

Dmitriy

unread,
Jun 15, 2017, 12:51:53 PM6/15/17
to tamal...@gmail.com, robotframework-users
Hi Tamali,

For fake data I’d suggest you to use faker.
But If you want to use variable files see docs 
So in your case ${FISTNAME}, ${LASTNAME}, etc. should be set in the python file 
f.e. 

var.py
```
FIRSTNAME = generate_fistname()
LASTNAME = generate_lastname()
...
```

Thanks,
Dmitriy

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Krzysztof Jozefowicz

unread,
Jun 16, 2017, 8:43:42 AM6/16/17
to robotframework-users
You got it almost right, as you imported vars from ../Resources/RandomNum.py,
those variables needs to be invoked using Robot syntax:
*** Settings ***
Library Selenium2Library
Variables ../Resources/RandomNum.py

*** Variables ***
${FIRSTNAME} =  ${firstname}
${LASTNAME} = ${lastname}
${EMAILID} = ${email}


assuming that RandomNum.py has following content:

firstname='John'
lastname='Doe'
email='sam...@email.com'

If you uncertain, use an editor with content assist which will help you to get variables from python into robot testcases (I don't know about RIDE but RED does it).
Reply all
Reply to author
Forward
0 new messages