Gau*_*ain 10 python selenium robotframework selenium-webdriver
*** Variables ***
${BROWSER} firefox
${URL} http://url/
${Delay} 0
Run Code Online (Sandbox Code Playgroud)
在我的settings.txt文件中,我有一个名为{BROWSER}的变量和关联值如上所示它是firefox
但我想要的是
*** Variables ***
@{BROWSERS} firefox chrome IE
${URL} http://url/
${Delay} 0
Run Code Online (Sandbox Code Playgroud)
像上面这样......所以当我首先运行测试套件时它将在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
Run Code Online (Sandbox Code Playgroud)
我运行这样的测试用例
$pybot test1 test2
我看到有两种方法可以做到这一点.
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}
Run Code Online (Sandbox Code Playgroud)
以下是您通过此测试获得的内容:
[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
==============================================================================
Run Code Online (Sandbox Code Playgroud)
2)另一种方式(我更喜欢)是将$ {BROWSER}变量保留为单个值,并使用您在命令行上给出的变量的新值多次调用测试用例:
[Mac]$ pybot --variable BROWSER:firefox ts.txt
[Mac]$ pybot --variable BROWSER:chrome ts.txt
[Mac]$ pybot --variable BROWSER:ie ts.txt
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7881 次 |
| 最近记录: |