Tuesday, May 5, 2009

Back to blogging ... Selenium and modal dialogs

It has been *way* too long since my last blog post, but another post is better late than never, right?

Most recently, I have struggled through automating a heavily AJAX-ey and fairly complex web interface using Selenium.

I have a setup that looks like this:
Visual Studio C# Express
NUnit
Selenium RC
IE Developer Toolbar, for identifying objects on the page
(and now AutoIT)
The occasional use of the Selenium IDE for speed and efficiency's sake.

I was having this particularly stubborn problem with a little dialog that popped up to confirm completion of some action, such as "User profile saved successfully". To this day, I am not 100% certain that I can identify what to call this guy: A pop-up? Alert? Confirmation? IE modal dialog?

Selenium IDE did not record or recognize in any way that this dialog exists. Further, my IE developer toolbar does not recognize this dialog when it's up, either. This all makes identifying it a bit difficult.

In my Selenium script, I tried identifying it as a pop-up, I tried identifying it as an alert, confirmation, and prompt, and none of them worked. My research indicated that this might be an "IE modal dialog" -- which is not supported by Selenium.

As I reached out to the agile-testing Yahoo group for help, I asked the developers how this dialog was being created. They showed me some code that simply called a javascript alert. I am still a little confused about that part, since Selenium RC should capture javascript alerts and close them. (Eventually I figured out that if the alert was called without a page redirect, Selenium behaved as expected, but if it was called as part of a page redirect function, Selenium failed to get it.)

Here is what the code that calls this dialog looks like:



The only difference between that and a similar dialog that Selenium correctly handles are those couple of lines that do the redirect ("parent.SetIframeMainModule"). I am still unclear about why that throws a wrench into my Selenium script, but the bottom line was that my Selenium script was not running!

Chris McMahon responded to my thread on the agile testing list that he had successfully used AutoIT to "hit it with a hammer". After a little bit of searching online, I found a blog post where someone else had used this tool -- in this case, the poster created an executable that looked for windows with certain visible text, and just closes them. This script runs separately from the Selenium test, just constantly polling the windows. It's an ugly hack, but when I tried it, it worked and allowed my Selenium tests to run.

To give proper credit, here is a link to the blog that posted this particular solution:

Get rid of those pesky IE dialogs with AutoIt

I would still love to hear about more graceful solutions ... I understand that Watir has found a way to handle these types of issues, and would love to see Selenium also be able to handle them. Please comment if you have solved a similar problem in a different way!

1 comment:

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!