4
votes

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)

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. Thanks in advance for the help!

3
You are using which library of selenium.. ? Java or selenium.. ? - Mayur Agarwal
Hi, Sorry for the omission. I am'm using Robot Framework with Python and Selenium2Library. - Dwayne Pindling
Do you want five separate windows, or do you want a single window? If you're just testing availability, do you need any windows at all? You can just do a REST request to the page to see if it's available. - Bryan Oakley
I have updated my answer, Please check once if it might help you... - Mayur Agarwal
@BryanOakley : If possible, I would prefer to not have a window at all. How can I implement a REST request? - Dwayne Pindling

3 Answers

4
votes

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). 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 ***
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
3
votes

you can use Execute Javascript Keyword like:

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

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