Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we pass different browser at once in robotframework

*** Variables ***

${BROWSER}          firefox
${URL}              http://url/
${Delay}            0  

in my settings.txt file i have a variable named {BROWSER} AND associate value as shown above it is firefox

but what i want is

*** Variables ***

@{BROWSERS}         firefox  chrome  IE  
${URL}              http://url/
${Delay}            0  

something like above... so when i run test-suite first it will run in firefox and after completion of all testcases it will close firefox and will open chrome and run all the test cases again on chrome browser ..and so on after this it will run on IE

so how could we do this?

I don't want to do it manually (I mean by passing one by one or by editing txt file). fully automatically.... once i run the test it will automatically test in all the browsers.

PS: this is in settings.txt file and i have two folders in which i have test.txt files. so there is the main problem ..i have to iterate these folders in a loop

|-- main.py
|-- settings.txt    //in this file i have browser variable (or Array)
|-- test1
|   |-- testl.txt
|   |-- test1_settings.txt  //this will contain all the variables and user defined keyword related to test1 and 
|-- test2
|   |-- test2.txt    
|   |-- test2_settings.txt  //same as test1

i run test cases like this $pybot test1 test2

like image 894
Gaurav Jain Avatar asked Jan 07 '14 06:01

Gaurav Jain


1 Answers

I see 2 ways to do it.

1) loop over your browser and call a keyword that do your test:

*** Variables ***
@{BROWSERS}          firefox  chrome  IE

*** test cases ***
test with several browser
    :FOR  ${browser}  IN   @{BROWSERS}
    \  log to console  call keyword that does your test with ${browser}

Here is what you get with this test:

[Mac]$ pybot .
Browser.Ts
==============================================================================
test with several browser                                             
call keyword that does your test with firefox
call keyword that does your test with chrome
call keyword that does your test with IE
test with several browser                                             | PASS |
------------------------------------------------------------------------------
Browser.Ts                                                            | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================

2) another way (which I prefer) is to keep your ${BROWSER} variable with a single value and call your test case several time with a new value for the variable that you give on the command line:

[Mac]$ pybot --variable BROWSER:firefox ts.txt
[Mac]$ pybot --variable BROWSER:chrome ts.txt
[Mac]$ pybot --variable BROWSER:ie ts.txt
like image 174
Laurent Bristiel Avatar answered Oct 14 '22 13:10

Laurent Bristiel