verifyAlertNotPresent() in selenium ide halts the execution on failure - selenium

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.

Related

Running RobotFramework Tests on Sauce Labs - error with timing out

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

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.

Selenium finds element only when I manually click Execute

I need to click on the button automatically. Code:
<tr>
<td>click</td>
<td>css=button</td>
<td></td>
When I click "Play current test case" it does not finds the element. But when I click "Find" after that - it does, and if I click Execute - it clicks on it!
Log:
[info] Executing: |click | css=div.sometag > p | |
[info] Executing: |pause | | 2000 | // Same error with pause & without it
[info] Executing: |clickAndWait | css=button | | // Auto executing
[error] Element css=button not found // Fails
[info] Executing: |click | css=button | | // I click on "Execute" manually - OK!
Why?
Have you tried to insert "waitForElementPresent|css=button|" before the click statement? This might help.
You actually need to use the class selector. So either div.button or .button, otherwise selenium probably is looking for an ID or an element name.
You could also try using a different type of locator, such as ID or XPath.
If we were able to see the HTML of the page you are interacting with, we could provide exact examples.

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}

Selenium IDE regex gives error "Threw an exception: missing ) after argument list"

In my test case I am trying to capture the dynamic state id from the url of current web page.
My Selenium IDE code is:
storeLocation | myLocation
echo | ${myLocation}
myLocation returns https://stage.abcx.com/ui/States/ManageTitle.ddx? action=view&stateid=76702
storeEval | re=/^sid/;re.exec(${myLocation}) | new
echo | ${new}
The error I keep getting is
[error] Threw an exception: missing ) after argument list
I have searched the net to find what's wrong with my code but could not figure out the issue.
Am new to Selenium and regex would appreciate any help.
Thanks!
You can try to replace
storeEval | re=/^sid/;re.exec(${myLocation}) | new
with:
storeEval | /\\d*$/.exec(storedVars['myLocation']) | new
new will contain all last digits from myLocation. Some info about the difference between ${x} and storedVars['x'] can be found here.