Reputation: 195
I want to run my test case with multiple test data (for different countries). Can this be achieved in the Robot framework? I have been working on RIDE IDE.
Below is sample code:
*** Settings ***
Suite Setup Login to Application
Suite TearDown Logout and Close The Browser
Resource import all required resource files
***Test Cases ***
Sample Test Case To Create Data for Multiple countries
Select Country USA #here am hard coding the country value, instead I want to pass it in run time
Enter all required data
Click Submit
#sample resource file that has the keyword for selecting Country Drop down and fill other details
*** Keywords ***
Select Country
[Arguments] ${value}
Select From List By Label ${locator} ${value}
Input Text locator text value
I tried to pass the arguments in test case but it says sanity check fails. Reset changes in the RIDE IDE the moment I add arguments at the Test case level.
I am using Python 2.7.14, RIDE 2.0a1.
Upvotes: 8
Views: 64300
Reputation: 39
A good approach for a task of this nature, is to use Templates. See Test Template with Robot Framework
Upvotes: 1
Reputation: 233
If you are using pybot command, use one of the bellow Syntaxes
pybot --variable Variable:Value ScriptName.txt
OR
pybot -v Variable:Value ScriptName.txt
Multiple Variable
pybot -v Variable1:Value -v Variable2:Value ScriptName.txt
You can access the command line variable value directly in your script without declaring and re-assigning.
Example.
pybot -v userId:admin -v password:123admin123 testLoginScript.txt
Upvotes: 1
Reputation: 20077
Add a variable with the target country, use it in the case, and set its value on run start. Only the relevant parts of your code:
# put this just after the end of the Settings section
*** Variables ***
${country} USA
*** Test Cases ***
Sample Test Case To Create Data for Multiple countries
Select Country ${country}
# the rest of your code
If your run it as is, it will use "USA" as value; if you want to override, pass the other value on the CLI:
robot --variable country:Mexico your_file.robot
Upvotes: 9
Reputation: 6981
In the Robot Framework Userguide there is an entire chapter on Configuring the Execution of Robot Framework. In this chapter there is a section on passing variables via the command line.
An example:
robot --variable OS:Linux --variable IP:10.0.0.42 my_test_suite_file.robot
and then you can use the variables ${OS}
and ${IP}
at any point in your scripts as they are Global variables.
Upvotes: 22