Running RobotFramework Tests on Sauce Labs - error with timing out - selenium

I have existing selenium tests written in Robot IDE Framework that I'm trying to run in Sauce Labs.
I'm using the sample test from this tutorial to see if I can get at least one test running. http://datakurre.pandala.org/2014/03/cross-browser-selenium-testing-with.html
The test passes locally, and passes all the tests on Sauce Labs, but then times out and gives and error, "Test did not see a new command for 90 seconds. Timing out.
error" because it's not disconnecting Remote Web Driver.
I've tried all of these, together and separately at the end of the "Close test browser" function:
Close all browsers
Process close
Stop selenium server
I've also tried adding ((RemoteWebDriver) getCurrentWebDriver()).quit() in one of the python functions that runs during the closing process. I'm new to Selenium and Robot Framework, so I'm not sure how to grab the Remote Web Driver.
Here is the code, in case that helps:
*** Settings ***
Test Setup Open test browser
Test Teardown Close test browser
Resource ../../Keywords/super.txt
Library Selenium2Library
Library ../../Library/SauceLabs.py
*** Variables ***
${LOGIN_FAIL_MSG} Incorrect username or password.
${COMMAND_EXECUTOR} http://username:key#ondemand.saucelabs.com:80/wd/hub
${REMOTE_URL} http://username:key#ondemand.saucelabs.com:80/wd/hub
${DESIRED_CAPABILITIES} username:name,access-key:key,name:Testing RobotFramework,platform:Windows 8.1,version:26,browserName:CHROME,javascriptEnabled:True
*** Test Cases ***
Incorrect username or password
[Tags] Login
Go to https://saucelabs.com/login
Page should contain element id=username
Page should contain element id=password
Input text id=username anonymous
Input text id=password secret
Click button id=submit
Page should contain ${LOGIN_FAIL_MSG}
[Teardown]
*** Keywords ***
Open test browser
Open browser http://www.google.com ${BROWSER} \ remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
Close test browser
Run keyword if '${REMOTE_URL}' != '' Report Sauce status ${SUITE_NAME} | ${TEST_NAME} ${TEST_STATUS} ${TEST_TAGS} ${REMOTE_URL}
Close all browsers
Process close
Stop selenium server

You shouldn't need to do anything special to close down the connection. My guess is, there's something in your test that is preventing the browser from being closed. My recommendation is to start with a simpler example, and start from the command line. Get that working, and then work your way up to being able to run something more complex from within RIDE.
Here is a working example where I removed all of the extra stuff in the test. I am able to run this both from the command line and via RIDE on Windows. You'll have to add in your own key, however:
*** Settings ***
| Library | Selenium2Library
*** Variables ***
| #{_tmp}
| ... | name:Testing RobotFramework Selenium2Library,
| ... | browserName:internet explorer,
| ... | platform:Windows 8,
| ... | version:10
| ${CAPABILITIES} | ${EMPTY.join(${_tmp})}
| ${KEY} | <put your username:key here>
| ${REMOTE_URL} | http://${KEY}#ondemand.saucelabs.com:80/wd/hub
| ${URL} | https://saucelabs.com/login
| ${LOGIN_FAIL_MSG} | Incorrect username or password.
*** Test cases ***
| Example of connecting to saucelabs via robot
| | [Setup]
| | ... | Open Browser
| | ... | ${URL}
| | ... | remote_url=${REMOTE_URL}
| | ... | desired_capabilities=${CAPABILITIES}
| |
| | Page should contain element | id=username
| | Page should contain element | id=password
| |
| | Input text | id=username | anonymous
| | Input text | id=password | secret
| | Click button | id=submit
| |
| | Page should contain | ${LOGIN_FAIL_MSG}
| |
| | [Teardown] | Close all browsers

Related

Chrome Selenium IDE 3.4.5 extension "execute script" command not storing as variable

I am trying to create a random number generator:
Command | Tgt | Val |
store | tom | tester
store | dominic | envr
execute script | Math.floor(Math.random()*11111); | number
type | id=XXX | ${tester}.${dominic}.${number}
Expected result:
tom.dominic.0 <-- random number
Instead I get this:
tom.dominic.${number}
I looked thru all the resources and it seems the recent selenium update/version has changed the approach and I cannot find a solution.
I realize this question is 2 years old, but it's a fairly common one, so I'll answer it and see if there are other answers that address it.
If you want to assign the result of a script run by the "execute script" in Selenium IDE to a Selenium variable, you have to return the value from JavaScript. So instead of
execute script | Math.floor(Math.random()*11111); | number
you need
execute script | return Math.floor(Math.random()*11111); | number
Also, in your final assignment that puts the 3 pieces together, you needed ${envr} instead of ${dominic}.

verifyAlertNotPresent() in selenium ide halts the execution on failure

I have written a script to Verify that alert is not present using verifyAlertNotPresent command. Using this command as I know execution should not stop even if alert is present and should continue but it halts the execution. My script is given below.
forXml | file:///E:/XML files/NAA_StateZip.xml
open |
clickAndWait | link=NAA Click & Lease
type | name=_OWNER | sdfsdf
type | name=OWNERFAX | 1234556
fireEvent | name=OWNERFAX | blur
verifyAlertNotPresent | Error: Invalid input format Please re-enter area code and phone number |
close
selectWindow | null
endForXml
When I am running this script Log shows this.
[info] Executing: |type | name=OWNERFAX | 1234556 |
[info] Executing: |fireEvent | name=OWNERFAX | blur |
[info] Executing: |verifyAlertNotPresent | Error: Invalid input format Please re-enter area code and phone number | |
[error] true
[info] Executing: |close | | |
[error] There was an unexpected Alert! [Error: Invalid input format Please re-enter area code and phone number]
[info] Test case fail
Please provide solution to this as I want to run this script for set of data.
To handle alerts using Selenium IDE, you will have to use 'assertFoo(pattern)' function. If you fail to assert the presence of a pop-up your next command will be blocked and you will get an error. Look at the Docs.

Robot Framework what is wrong with my indentation?

I read that you can use a pipe-separated format for Robot Framework tests, but in my code:
*** Settings ***
| Documentation | A test suite with a single test for valid login.
| Library | Selenium2Library
| Resource | AdminResource.txt
*** Variables ***
| ${LOGIN URL} | http://local.econnect-admin.com/
| ${BROWSER} | ff
| ${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button
*** Test Cases ***
| Valid Login
|| Open Browser To Login Page
|| Input Text | a11y-username | username
|| Input Text | a11y-password | password
|| Click Log in
|| Welcome Page Should Be Open
*** Keywords ***
| Open Browser To Login Page
|| Open Browser | ${LOGIN URL} | ${BROWSER}
|| Maximize Browser Window
|| Wait Until Page Contains Element | ${Login button} | 5s
| Click Log in
|| Click Element | ${Login button}
| Welcome Page Should Be Open
|| Location Should Be | ${LOGIN URL}
|| Wait Until Page Contains | Accounts | 5s
|| Page Should Contain | Accounts
When ran the code gives a variety of errors:
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${LOGIN URL} | http://local.econnect-admin.com/' failed: Invalid variable name '|${LOGIN URL} | http://local.econnect-admin.com/'.
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${BROWSER} | ff' failed: Invalid variable name '|${BROWSER} | ff'.
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button' failed: Invalid variable name '|${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button'.
It also tells me that each line of my test cases (including the name of the test case) contain to keywords.
Have I wrongly formatted my test scripts, or am I misinformed about pipe-separated formatting?
Edit - In another question the answer was given using this format
Thanks in advance.
You must have spaces between pipes. Consider this line:
|| Open Browser | ${LOGIN URL} | ${BROWSER}
you need to change it to this:
| | Open Browser | ${LOGIN URL} | ${BROWSER}
From the user guide:
Pipe and space separated lines are recognized by the mandatory leading
pipe, but the pipe at the end of the line is optional. There must
always be at least one space on both sides of the pipe (except at the
beginning and end) but there is no need to align the pipes other than
if it makes the data more clear.

assertText a message that has line break in Selenium IDE

I am new in Selenium IDE and need to assertText a value that has line break. Example:
Actual Message to assertText:
Hello
World
store | Hello <br/> World | txtValue
assertText | id=label | ${txtValue}
Please help.
Pass your id=label into a variable, remove the line breaks, then run an assertion against the variable.
Store expected text:
store | Hello World | txtValue
Store page text:
storeText | xpath=(//*[#id=label]) | labelValue
Remove line breaks from page text:
echo | javascript{storedVars.labelValue = storedVars.labelValue.replace(/(\r\n|\n|\r)/gm,"")} |
Assert your expected text = your page text:
assertExpression | javascript{storedVars.txtValue==storedVars.labelValue} | true
Following pattern matching worked for me on Selenium IDE 2.5.0
regexp:Hello\s+World

Keeping the focus after opening a new window in the Selenium IDE

I'm having a problem retaining the focus after using the openWindow command in the IDE. This problem only applies when a second test case within the same test suite tries to interact with the newly-opened window. For example, I have a test suite consisting of separate test cases to do the following:
Log into site A
Enter some transactional data
Submit the transaction for approval
Open a new window and log into site B
Approve the transaction in site B and close the window
Continue processing the transaction in site A
If I do the test case 5 "site B" actions in the same test case as the "openWindow" (ie. merge test cases 4 and 5) then all commands execute without error. If I do the same actions in a different test case then the new window loses the focus and all Selenium commands are directed back to the original window.
The interesting part of this is trying to identify and reselect the "new" window in step 5.
Executing "selectWindow name=siteB_URL" in test case 5 results in the error message "Window does not exist. If this looks like a Selenium bug...".
I then figured I'd call storeAllWindowNames and echo the results to at least see the window names Selenium knows about at various points. If I do this as the last two commands in test case 4 I get the expected result - "echo ,siteB_URL" is logged. If I do the same thing as the first two lines in test case five I get "echo ". This is the part that gets me - simply changing test cases seems to lose the reference to the new window.
Has anyone come up with a workaround or solution to this problem in the Selenium IDE?
I've spent several hours this morning scouring the web and various forums looking for suggestions to no avail.
Thanks in advance,
Glenn
4-7-12 - Update - here's a simplified example of the scenario above:
[info] Executing: |openWindow | http://www.google.com.au | google2 |
[info] Executing: |selectWindow | google2 | |
[info] Executing: |storeAllWindowNames | allWindows | |
[info] Executing: |echo | ${allWindows} | |
[info] echo: ,google2
[info] Changed test case
[info] Executing: |storeAllWindowNames | allWindows | |
[info] Executing: |echo | ${allWindows} | |
[info] echo:
[info] Executing: |selectWindow | name=google2 | |
[error] Window does not exist. If this looks like a Selenium bug, make sure to read http://seleniumhq.org/docs/04_selenese_commands.html#alerts-popups-and-multiple-windows for potential workarounds.
Have you check it with following commands?
selectFrame | relative=up
selectFrame | iframe name
Try with option:
selectWindow()
Just provide the window title name within ().
For Ex:
Window Title is Testing, then
command : selectWindow
title : Testing
To know the title of the newly opened window follow the steps:
Go to the new window
Right click->view page source
Press ctrl+F.
Type title and search.
You will get the title of the new window.
I hope this helps...
Thanks
Sathiya
//on the original window...
command: store window handle
target: myVar
//...do whatever...
command:select window
target: handle=${myVar}