How to pass command line arguments (test data parameters) in Robot framework

Sailesh picture Sailesh · Jul 19, 2018 · Viewed 23.4k times · Source

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.

Answer

A. Kootstra picture A. Kootstra · Jul 19, 2018

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.