问题描述
*** Variables ***
${BROWSER} firefox
${URL} http://url/
${Delay} 0
在我的settings.txt文件中,我有一个名为{BROWSER}的变量,并且关联值如上所示,它是firefox
in my settings.txt file i have a variable named {BROWSER} AND associate value as shown above it is firefox
但是我想要的是
*** Variables ***
@{BROWSERS} firefox chrome IE
${URL} http://url/
${Delay} 0
类似上面的内容...因此,当我首先运行测试套件时,它将在Firefox中运行,并且在完成所有测试用例之后,它将关闭Firefox,并将打开chrome,然后在chrome浏览器上再次运行所有测试用例..依此类推在此之后它将在IE上运行
something like above... so when i run test-suite first it will run in firefox and after completion of all testcases it will close firefox and will open chrome and run all the test cases again on chrome browser ..and so on after this it will run on IE
那我们怎么办呢?
我不想手动进行操作(我的意思是一一传递或编辑txt文件).完全自动....一旦运行测试,它将在所有浏览器中自动进行测试.
I don't want to do it manually (I mean by passing one by one or by editing txt file).fully automatically.... once i run the test it will automatically test in all the browsers.
PS:这在settings.txt文件中,我有两个文件夹,其中有test.txt文件.所以主要的问题是..i必须循环访问这些文件夹
PS: this is in settings.txt file and i have two folders in which i have test.txt files. so there is the main problem ..i have to iterate these folders in a loop
|-- 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
i run test cases like this$pybot test1 test2
推荐答案
我看到了两种解决方法.
I see 2 ways to do it.
1)在浏览器上循环并调用进行测试的关键字:
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)另一种方式(我更喜欢)是将$ {BROWSER}变量保留为单个值,并使用在命令行中给出的变量的新值多次调用测试用例:
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
这篇关于我们如何在robotframework中一次通过不同的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!