Monday, March 24, 2008

Selenium and the Wii hunt

Selenium is a great tool for automating mouse clicks on web applications. It does AJAX and other nice things that some of the professional tools don't do. (aside: bye-bye Winrunner/SilkTest/QuickTest for your pricy way of testing web applications.)

Anyway, here's the story. About 2 years ago I was looking for a Wii (around November 2006). As like everyone else at the time, I wanted a Wii, but couldn't find one. I remember checking about 5 different sites that had online inventory, so I looked for a tool to do grep (search) of those shopping sites around Ontario. Futureshop, Best Buy, etc...

Selenium fit the bill. So I did a script to check all the sites every 20 seconds to check for stock. This was running on an old Windows XP box in my basement (I have gone to mac, so my old desktop is now my play-time server). I setup the script up to send me a text message to my cell when one was available. I was quite proud of the fact that my script was constantly checking the sites, but unfortunately weeks went by without a hit.

Then, while driving on the highway from Waterloo to Toronto I get a buzz on my cell phone. 100 Wii's available at Futureshop. Since I was in my car and my phone is a cheapy nokia flip phone, I couldn't exactly buy it.

Remember how I said the script would send me a text message every minute; I only got ONE text message. ONE? ONE! When I got home, I looked at the logs. Since the script was checking every 20 seconds, but was setup to send a text every minute while the number was not zero (for the geeks out there -- while wii_qty != 0), the logs showed a fast and steady decrease in the number of wii's during that minute. 100, 81, 65, 43, 27, 8, 0.

So, what did I learn from this?
1) I should have tested my logic first. The reality was I wasn't looking for a Wii. I was looking to purchase a Wii. If I wrote a charter to my activity, I would have recognized this flaw. So, I should have setup the script to automatically PURCHASE the Wii once one was available.
2) Notify me when I owned one.
3) I wasn't the only one with a script looking for a Wii. :-)

I had to wait until March 2007 until I got a Wii... and I got it the old fashion way; by driving clear across town after a phone call blitz to about 20 places that sold Wii's.