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!
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
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");
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
Related
I try to run my testing but it doesn't work.
here my code:
*** Settings ***
Library RequestsLibrary
Library Collections
Library JSONLibrary
*** Variables ***
${base_url} https://reqres.in
*** Test Cases ***
Get user test
Run Keywords
[Tags] get
${resp}= get ${base_url}/api/users/2
Status Should Be OK ${resp}
Should Be Equal As Strings ${resp.status_code} 200
and there's always a sign that "no keyword with name ____ found"
For this Test case i am getting below error "ValueError: Argument 'url' got value 'www.google.com' that cannot be converted to None." in Ubuntu OS but not in windows
*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
*** Variables ***
${Browser} FF
*** Test Cases ***
Open_browser www.google.com ${Browser}
*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
*** Variables ***
${Browser} FF
*** Test Cases ***
test
Open_browser https://www.google.com ${Browser}
your robot file itself is wrong , you should provide a test name and also provide https://
I have faced the same issue.
You need to setup again.
Uninstall Python, and IDE
Again install Python, Robot-Framework, and Selenium.
Set the Python path and web driver path
Now restart the System.
In My case, it is working fine by following these steps.
I am building automation for the browser (from chromium kernel)
while locating element from some internal page such as: chrome://settings/
I can get xpath of "Autofill" by //[#id="autofill"]
But when I run the script by Robot framework, it said "Element with locator '//[#id="autofill"]' not found."
Here is the simple script:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
*** Test Cases ***
Open URL in Google Chrome
Open browser chrome://settings/ chrome
Click Element //*[#id="autofill"]
*** Keywords ***
https://imgur.com/a/FAJoYji
Thank you so much!
here is my first and simple code in robot framework , I am just trying to input text in google searchbox and then close the browser but it keeps on failing.
*** Settings ***
Documentation Suite description
Library Selenium2Library
*** Variables ***
${Browser} chrome
${URL} https://www.google.com/
${text} ab
*** Test Cases ***
TC 001 Browser Open and Close
Open Browser ${URL} ${Browser}
Set Browser Implicit Wait 5
Input Text name=q ab
Close Browser
error message -
WebDriverException: Message: unknown error: call function result missing 'value'
(Session info: chrome=80.0.3987.132)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17763 x86_64)
strong text
Strange thing if i run only below it works fine so i am suspecting it has to do with step where i am trying to insert text in google search box
*** Settings ***
Documentation Suite description
Library Selenium2Library
*** Variables ***
${Browser} chrome
${URL} https://www.google.com/
${text} ab
*** Test Cases ***
TC 001 Browser Open and Close
Open Browser ${URL} ${Browser}
Set Browser Implicit Wait 5
Close Browser
You don't have the correct chromedriver version for your version of chrome. The error shows you're using chrome 80, but chromedriver 2.33. You need to be using chromedriver version 80.
I want to use Chrome for automation test with Robot Framework. Here are my settings:
*User variables:*
name: webdriver.chrome.driver
value: C:\chromedriver_win32\chromedriver.exe
name: PATH
values: ......;C:\chromedriver_win32\chromedriver.exe
My code:
*** Settings ***
Library BuiltIn
Library Selenium2Library
Library SikuliLibrary
Library OperatingSystem
*** Variables ***
${HOST} = VM
${URL} = http://VM.com
${BROWSER} = Chrome
*** Test Cases ***
Begin Web Test
Open Browser ${URL} ${BROWSER}
maximize browser window
After execution of command: pybot test.robot:
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No brows
er is open
Test Case FException
AttributeError: "'Service' object has no attribute 'process'" in <bound method
Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x000000
0003670278>> ignored
Test Case | FAIL |
Setup failed:
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Plea
se see https://sites.google.com/a/chromium.org/chromedriver/home
------------------------------------------------------------------------------
What is wrong here?
Thank you
"chromedriver' executable needs to be in PATH" means that the location of chromedriver needs to be in the path. In your case, path needs to be "...;C:\chromedriver_win32". PATH contains folders, not executables.
Download Chromedriver.exe from its official website, extract the .exe file and copy this .exe file in scripts folder of Python installation, e.g. C:\Python36\Scripts
After this, add this scripts path in Environment variable, as below:
and now execute your test case.