我正在尝试使用机器人框架测试模板功能,并且遇到了一些困难。
我目前的测试包括打开5个不同的网站(声明为变量)
这是我的代码:
*** Settings ***
Library Selenium2Library
Library OperatingSystem
Library String
Library Collections
Test Template Open URL
*** Variables ***
${URL1} http://montrealgazette.com/
${URL2} https://www.usatoday.com/
${URL3} http://www.foxnews.com/
${URL4} http://www.cnn.com/
${URL5} https://ca.reuters.com/
*** Test Cases ***
Validate Availability
${URL1}
${URL2}
${URL3}
${URL4}
${URL5}
*** Keywords ***
Open URL
[Arguments] ${URL}
Open Browser $[URL] Chrome
当我运行此代码时,会打开5个单独的空白浏览器窗口。如果有更好的方法,请告诉我。 在此先感谢您的帮助!
答案 0 :(得分:2)
您可以使用Execute Javascript关键字:
*** Settings ***
Library Selenium2Library
Library OperatingSystem
Library String
Library Collections
Test Template Open URL
*** Variables ***
${URL1} http://montrealgazette.com/
${URL2} https://www.usatoday.com/
${URL3} http://www.foxnews.com/
${URL4} http://www.cnn.com/
${URL5} https://ca.reuters.com/
*** Test Cases ***
Validate Availability
Open URLs In New Tab ${URL1} ${URL2} ${URL3} ${URL4} ${URL5}
*** Keywords ***
Open URLs In New Tab
[Arguments] @{URL}
:FOR ${eachUrl} IN @{URL}
\ Execute Javascript window.open(${eachUrl},"_blank");
答案 1 :(得分:1)
您需要更改的唯一部分是 *关键字* 部分
*** Keywords ***
Open URL
[Arguments] ${URL}
Open Browser ${URL} Chrome
而不是方括号使用大括号
答案 2 :(得分:1)
您似乎没有缩进测试用例的内容,这可能是问题(在您修复了Raj sattam's answer中提到的语法错误之后)。这几乎是我能看到的唯一错误。您也希望在关键字的声明中也这样做。
*** Test Cases ***
Validate Availability
${URL1}
${URL2}
${URL3}
${URL4}
${URL5}
如果仍然无法解决问题,您可以尝试将测试用例本身声明为模板化测试用例,而不是使用** Settings **
部分,如下所示:
*** Settings ***
Library Selenium2Library
Library OperatingSystem
Library String
Library Collections
*** Variables ***
${URL1} http://montrealgazette.com/
${URL2} https://www.usatoday.com/
${URL3} http://www.foxnews.com/
${URL4} http://www.cnn.com/
${URL5} https://ca.reuters.com/
*** Test Cases ***
Validate Availability
[Template] Open URL
${URL1}
${URL2}
${URL3}
${URL4}
${URL5}
*** Keywords ***
Open URL
[Arguments] ${URL}
Open Browser ${URL} Chrome