gpt4 book ai didi

python - 我们如何在机器人框架中一次通过不同的浏览器

转载 作者:太空狗 更新时间:2023-10-29 18:34:19 25 4
gpt4 key购买 nike

*** 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 文件)。完全自动....一旦我运行测试,它将自动在所有浏览器中进行测试。

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

最佳答案

我看到了 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

关于python - 我们如何在机器人框架中一次通过不同的浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20965583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com