Shivani Deshmukh
Shivani Deshmukh

Reputation: 65

how to run specific test cases in robot framework

I want to run some test cases of robot file. I have names of test cases stored in list and want to run only those.

Example:

${my_data_as_list}=    Create List

${my_data_as_list}= ['open browser','click link']

*** Test Cases ***

open browser

-----Open Browser    https://demo.nopcommerce.com/   Chrome

click link

-----click link  xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

input text

-----input text  id:Email     shivani

Close Browser 

-----Close Browser

Here I want to call only 2 test cases i.e. 'open browser' and 'click link' which can be generic like list data can be change so particular test case should get called.

As I am automating the things, above list of steps are random that can be anything sometimes 1st two test cases sometimes last two or all, anything so accordingly I want to execute. Just consider the case in python file you have a list of unknown names in it and you have created some functions of the same name so using for loop you can iterate the list and whatever the function name is present in the list that gets called sequentially. Same I want to do in robot file

List=[login, register,close]

For x in List:

Call x

//Now login gets called then register and then close upto the loop ends.

def login(): ....

def register (): ....

def calculate (): .... . .

More 10-20 functions

Upvotes: 0

Views: 3945

Answers (2)

FinlayL
FinlayL

Reputation: 196

If this is a temporary thing and you don't want to change the files you can specify the tests in the arguments of your robot command:

--test 'open browser' --test 'click link' --test 'input text'

Source: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-execution

Upvotes: 3

AntonioMJ
AntonioMJ

Reputation: 134

Why don't you use the tag capabilities of RobotFramework and use the exclude option in the execution command line.

${my_data_as_list}=    Create List

${my_data_as_list}= ['open browser','click link']

*** Test Cases ***

open browser

-----Open Browser    https://demo.nopcommerce.com/   Chrome

click link

-----click link  xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

input text

-----input text  id:Email     shivani

Close Browser 
[Tags]     noExec
-----Close Browser

Command line: robot --exclude noExec

See official explanation here: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#by-tag-names

Upvotes: 1

Related Questions