Selenium RC and Pop-up handling
Well its been a while since I found some time to get back to my blog. I started this blog anticipating at least one blog enty per week, but recently have been really busy at work that it took me almost 6 months to write my second blog entry.
I am not going to plan anything like this again and will try to find some time to write about my learnings while using Selenium RC with TestNG, Maven and Anthill Pro.
Recently I have been asked by one of the readers about the pop-up handling in Selenium in general and Selenium RC in specific. As per my understanding Selenium IDE does not support recording on the pop-ups because If the popup is a new window, i.e., not in the html body of the main winodw, Selenium IDE, Dom Inspector, and other Firefox plugins do not work. The reason is there are multiple document variables to handle and it might not be a good idea to record any popup window which make the event listener more complicated.
This would instruct selenium to click OK on the pop up that appears as a result of clicking the delete button. You can also assert on the pop up in the next statement. There is also a function available to verify that the alert is present.
isAlertPresent() - this would return a boolean (true/false) based on the alert existence
I have not used Selenium RC to verify the login dialogs but there are some functions available to handle pop ups like these.
e.g The following code will use the selectWindow, windowFocus and close functions to work on a pop up/dialog.
selenium.type("username", "user name");
Sometimes you might need to assert on the pop ups. e.g. you might want to assert that on deleting a button a pop up appears. You can use waitForPopUp to make sure that your test script waits for the pop up to appear and does not give you a time out error.
assertEquals("Delete Confirmation", selenium.getAlert());
If you have custom defined pop-ups then you might want to use Java Robot to do deal with custom define pop-ups. The Robot class is defined in java.awt package. You can control the mouse and keyboard events using Robot class. It is not an elegant solution but it works.
You can also use some other tools (AutoIt) to keep listening for certain events such as SSL security certificates or download dialogs and click on OK whenever these type of pop up appear.
There is another way of dealing with the file download pop ups. You can define a custom firefox profile and disable the file download pop up, so that it never appears during the test execution but still downloads the stuff on the hard disk which you can verify for testing purposes. You then launch selenium server with this custom firefox profile.
I hope that it will help you in dealing with pop ups. Please feel free to comment and ask questions.
Possibly related posts: (automatically generated)