2014-01-07 140 views
9
*** Variables *** 

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

在我settings.txt文件傳遞不同的瀏覽器我有一個名爲{}瀏覽器和準值,如圖上面的變量是火狐我們怎樣才能在一次robotframework

,但我想要的是

*** Variables *** 

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

像上面這樣的東西...所以當我運行測試套件時,它會運行在Firefox和所有測試用例完成後它將關閉Firefox,並將打開Chrome並在Chrome瀏覽器上再次運行所有測試用例。等此後它將運行在IE

那麼我們該怎麼做呢?

我不想手動做(我的意思是通過一個一個傳遞或編輯txt文件)。 全自動....一旦我運行測試,它會自動在所有瀏覽器中測試。

PS:這是在settings.txt文件中,我有兩個文件夾,其中我有test.txt文件。所以..我不得不遍歷這些文件夾在一個循環

|-- 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 

我運行測試用例這樣 $pybot test1 test2

回答

5

我看到2種方式來做到這一點的主要問題。

1)循環在你的瀏覽器,並調用完成測試關鍵字:

*** 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} 

這裏是你與這個測試得到:

[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)另一種方式(我喜歡)是保持您的$ {BROWSER}變量具有單個值,並將您的測試用例多次用您在命令行上給出的變量的新值調用:

[Mac]$ pybot --variable BROWSER:firefox ts.txt 
[Mac]$ pybot --variable BROWSER:chrome ts.txt 
[Mac]$ pybot --variable BROWSER:ie ts.txt 
+0

解決方案2應該工作,不是嗎?這就是我做這種事情的方式,我對此感到滿意。我開始與詹金斯進行測試,並且我想測試每個配置1個作業。 –

0

好吧我想我已經通過編寫一個簡單的腳本解決了這個問題。

我剛剛寫了一個程序,它將讀取文件settings.txt並找到@{BROWSER} firefox chrome IE 行,然後提取瀏覽器名稱和存儲到列表中。所以這個腳本會返回一個列表這樣的事情 [「火狐」,「鉻」,「IE」]

現在不是使用單pybot命令,我會在循環

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

使用settings.txt文件將包含兩個變量

${BROWSER}   firefox  #So default browser is firefox. you can leave it blank 
@{BROWSERS}   firefox chrome IE