waitForSomethingOtherThanElementPresent

Every Selenium assertion can start with assert, verify, or waitFor, according to the Selenium API docs. Yet many testers never need any waitFor assertion beyond the ubiquitous waitForElementPresent.  This post elucidates the usage of a different waitFor assertion–waitForNotAttribute – a non-intuitive name if ever there was one!

To understand how my Selenium IDE demo program works, first look at the page I “tested”–a very nice online alarm clock. Then “capture” the DOM source of the six large red digits. I did this via selecting (highlighting) the digits in Firefox, then selecting View Selection Source from the context (right-click) menu….


See those src attributes in the img tags? They indicate that I selected View Selection Source precisely at 8:09:19 PM. cb.gif is a blank, c8.gif is a large red 8, c0.gif is a large red 0, c9.gif is a large red 9, cpm.gif is a large red PM, etc. The clock updates in this page are achieved via Ajax changes to the img tags’ src attributes’ values.

My Selenium test case doesn’t really test anything–it just demos how waitForNotAttribute works….

AJAX-CHANGING-VALUES
setTimeout 65000
open http://onlineclock.net/
storeAttribute e@src minutes_digit_2
echo The second digit of minutes is: ${minutes_digit_2}
waitForNotAttribute e@src ${minutes_digit_2}
storeAttribute e@src minutes_digit_2
echo The second digit of minutes is: ${minutes_digit_2}

After opening the clock page, it uses storeAttribute to save the src attribute for the element with an id attribute of e (the second digit of the minutes displayed by the clock). That URL is then echo‘ed out to the log file. Then waitForNotAttribute is called, with the e element’s src attribute specified as the first argument. waitForNotAttribute will wait until the value of the specified attribute does NOT match the pattern specified by the second argument. In other words, waitForNotAttribute is going to wait until there’s a change to the minutes being displayed. Then, the program again captures the URL for the image file that displays the second digit of the minutes on display and echoes it out to the log file.

Note that I’ve used setTimeout with an argument of 65000 milliseconds. Since the minutes on display have to change every 60000 milliseconds, the waitForNotAttribute will always wait long enough even if the Selenium program begins executing right after a new minute starts.

And now for the demo! Don’t get impatient watching it! This demo is not about things happening–it’s about proper waiting!

Advertisements

About Mary Ann May-Pumphrey

I'm a software QA automation engineer, focusing primarily on Selenium/Webdriver automation of the front end of web apps. View all posts by Mary Ann May-Pumphrey

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: