How can we pass different browser at once in robotframework

后端 未结 2 862
醉话见心
醉话见心 2021-02-14 14:45
*** Variables ***

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

in my settings.txt file i have a variable named

相关标签:
2条回答
  • 2021-02-14 15:17

    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
    
    0 讨论(0)
  • 2021-02-14 15:33

    Ok I think I've solved this problem by writing a simple script.

    I Just wrote a program which will read the file settings.txt and find the line @{BROWSER} firefox chrome IE and then extract browsers name and store into a list . so this script will return a List something like this ['firefox', 'chrome', 'IE']

    now instead of using single pybot command I'll use it in a Loop

    for browser in browsers:
            call(['pybot','--variable'] +['BROWSER:%s'%browser] + test_args) 
    

    settings.txt file will contain two variable

    ${BROWSER}          firefox      #So default browser is firefox. you can leave it blank
    @{BROWSERS}         firefox  chrome  IE
    
    0 讨论(0)
提交回复
热议问题