如何在robotfram中同时传递不同的浏览器

2024-04-27 21:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

*** Variables ***

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

在我的settings.txt文件中,我有一个名为{BROWSER}的变量,上面显示的关联值是firefox

但我想要的是

*** Variables ***

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

像上面这样的。。。因此,当我首先运行测试套件时,它将在firefox中运行,并且在完成所有测试用例后,它将关闭firefox并打开chrome,然后在chrome浏览器上再次运行所有测试用例,依此类推,它将在IE上运行

那我们怎么能这样做呢?

我不想手动操作(我的意思是逐个传递或编辑txt文件)。 完全自动。。。。一旦我运行测试,它将在所有浏览器中自动测试。

注:这是在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


Tags: 文件browsertxthttpurlsettings测试用例variables
2条回答

好吧,我想我已经通过写一个简单的脚本解决了这个问题。

我刚刚编写了一个程序,它将读取文件settings.txt并找到@{BROWSER} firefox chrome IE行 然后提取浏览器名称并存储到列表中。所以这个脚本将返回这样的列表 ['firefox','chrome','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

我看到了两种方法。

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

相关问题 更多 >