2014-01-07 139 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