how to share ${variables} between two test or how to set ${variables} in "resource" evaluating keyword in order to share between two test?

3,384 views
Skip to first unread message

Andrea Bisello

unread,
Jan 20, 2016, 10:01:28 AM1/20/16
to robotframework-users
Hi

reading http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#variable-priorities-and-scopes i understand that i can use resource.robot to share variables, but i need to create a variable evaluating a keyword. if i try to do this in variables table, variables value is the keyword name, not the keyword returned value.

i try to explain myself better.

my testsuite has some test that need to share information between those. For example, my website permits to create user , so,  testing my website, i need to share the same ID in order to CREATE, LOCATE and DELETE the same created user.

i want to split CREATE  , LOCATE and DELETE in three test case

In my case, the ID is generated by datetime

${id}= Get Current Date    result_format=%d-%m-%Y-%H:%M

*** test cases

| Create user
|    |   Input Text    |  myLocator    | ${id}

| User should be created
|    |    Page Should Contains    |    ${id}


| Delete Created User
|    |       

how to create ${id} and share between test?

i cannot use resource file becasue if i put

${id}= Get Current Date    result_format=%d-%m-%Y-%H:%M

in *** variables *** area,  Get Current Date    result_format=%d-%m-%Y-%H:%M will be considered as a String

i can put

${id}= Get Current Date    result_format=%d-%m-%Y-%H:%M

at the first phase of the first test, but the other test will now view ${id}

some advice?

thanks

Andrea Bisello

unread,
Jan 20, 2016, 10:13:25 AM1/20/16
to robotframework-users
using http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-set-test-suite-global-variable-keywords i make a workaround

i created a fake test that generate the ID and assign it to the Suite scope

* Test Cases
Prepare Variables
    ${d}=    Get DateTime Id
    Set Suite Variable ${d}

then when i need it in a test i obtain variables from the scope

${username} = Get Variable Value ${d}


this workaround works, but i would not to use a test in order to prepare variable.

Hélio Guilherme

unread,
Jan 20, 2016, 10:23:34 AM1/20/16
to robotframework-users
You should do that in a Suite Setup section, that way all tests will have the initial setup.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#suite-setup-and-teardown

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

Kevin O.

unread,
Jan 20, 2016, 11:44:26 AM1/20/16
to robotframework-users
If you define your variables in a variable file, the variables can be defined at runtime in Python or Java.

An simple variable file, defining the variable id in the same way you are, would look like this:
import datetime

id = datetime.datetime.now().strftime("%d-%m-%Y-%H:%M")

Andrea Bisello

unread,
Jan 20, 2016, 11:47:09 AM1/20/16
to robotframework-users
Thanks Helio,

i know this, but how should i store variables?

if i do :

*** Settings ***
Suite Setup prepare data

* Keywords
Prepara le variabili
    ${id}=    Get DateTime Id
    Open Browser     ${LOGIN URL}    ${BROWSER}

then when test needs to use ${id} , this are not avaiable.

sure, i can Set Suite Variable , but i think this is a little tricky. Maybe this is the right way.
Reply all
Reply to author
Forward
0 new messages