简体   繁体   English

使用Robot Framework的测试模板

[英]Test Template with Robot Framework

I am attempting to utilize the Robot Framework Test Template function and have been experiencing a little difficulty. 我正在尝试利用机器人框架测试模板功能,并且遇到了一些困难。

My current Test consist of opening 5 different websites (declared as variables) 我当前的测试包括打开5个不同的网站(声明为变量)

Here is my code: 这是我的代码:

*** 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

When I run this code, 5 separate blank browser windows are opened.If there is a better way to do this, please let me know. 当我运行此代码时,会打开5个单独的空白浏览器窗口。如果有更好的方法,请告诉我。 Thanks in advance for the help! 先谢谢您的帮助!

you can use Execute Javascript Keyword like: 您可以使用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");

The only part you need to change is the * Keywords * section 您需要更改的唯一部分是*关键字*部分

*** Keywords ***
Open URL
    [Arguments]  ${URL}
    Open Browser    ${URL}     Chrome

Instead of square brackets use braces 代替方括号,使用大括号

You don't seem to have indented your test case's content, which could perhaps be the problem (after you've fixed the syntax error mentioned in Raj sattam's answer ). 您似乎没有缩进测试用例的内容,这可能是问题所在(修复了Raj sattam的答案中提到的语法错误之后)。 That's pretty much the only mistake I can see. 这几乎是我所能看到的唯一错误。 You'll want to do the same in your keyword's declaration as well. 您也需要在关键字的声明中执行相同的操作。

*** Test Cases ***
Validate Availability
    ${URL1}
    ${URL2}
    ${URL3}
    ${URL4}
    ${URL5}

If that still doesn't fix it, instead of using the ** Settings ** section, you may try to declare the test case itself as a templated test case, like this: 如果仍然不能解决问题,则可以尝试将测试用例本身声明为模板化测试用例,而不是使用** 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM