6098 comments
2357 subscribers
6256 on Twitter
Subscribe! Feed reader E-mail

The joys of development with Selenium web-testing

I’ve started using the Selenium web-testing framework as part of regular development, and I like it. Selenium makes it easy to automate testing web applications, but it’s also useful for developing web applications.

I was working on improving the administrative interface of a Drupal site. To test the new features, I needed to switch back and forth between different users, and I needed to move nodes through a workflow. Masquerade made it a little bit easier to switch between user roles without logging out and logging in, but there was still a lot of clicking and waiting involved. Selenium made it easy to record and tweak the steps I took, and I could even add assertions so that I didn’t have to check things myself.

Timestamps helped me doublecheck that new data was successfully submitted, and that my e-mail messages weren’t using the old data. Here’s how to store a timestamp:

storeEval { var stamp = new Date(); var year = stamp.getYear() + 1900; var month = stamp.getMonth() + 1; var day = stamp.getDate(); var hours = stamp.getHours(); var mins = stamp.getMinutes(); var time; var secs = stamp.getSeconds(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (mins < 10) { mins = "0" + mins; } if (secs < 10) { secs = "0" + secs; } timestamp = "" + year + "-" + month + "-" + day + " " + hours + ":" + mins + ":" + secs; } timestamp

Then I can refer to that timestamp when filling out forms, like this:

type Node title ${timestamp}

I can check if the timestamp is present on a page:

assertTextPresent Node title ${timestamp}

I thought I would get impatient with the slow pace of web testing compared to directly testing the underlying models using code (Simpletest rocks for this). The visual feedback from watching my browser step through the tests helped me appreciate the time I saved compared to clicking through things myself. (And I had extra time to write notes in Emacs or comment my code while the tests are running!)

The Stored Variables Viewer (http://seleniumhq.org/download/) plugin was great for viewing timestamps, saved HTML snippets, and other things stored during test cases. In a pinch, it’s a decent way to explore something in the Selenium IDE context – store a variable, then view it.

Selenium IDE is a free Firefox plugin that you can get at http://seleniumhq.org/download/ Good stuff!

Short URL: http://sachachua.com/blog/p/22530
  • http://www.trajano.net/ Archimedes Trajano

    Awesome. I’ve used Selenium back in my old old project which had a GUI. Tweaked the thing silly, but I personally never got around doing a full automated integration test because of time and it wasn’t really possible because we couldn’t automate the deployment to our test environments (since they’re on different networks behind firewalls)

    What I have done at the very least was to get a developer to manually run the test as part of the development smoke test before we release to the test team.

On This Day...

  • 2012: Weekly review: Week ending October 12, 2012 — Friends from the Netherlands are over here, so it’s been pretty busy! From last week’s plans Business [X] Earn: [...]
  • 2010: Toaster’s toasted — Our wedding vacation was a whirlwind of cooking, thanks to the talents of my middle sister Kathy and our family [...]
  • 2008: Happy BlueDay to me! — Today is my one-year anniversary at IBM! Yes, I know, I’ve been on the IBM network for a couple of [...]
  • 2007: First day of work — Like most (sane) graduates, I’m a little anxious about this real life thing, but I’m confident that it will work out [...]
  • 2005: Bought winter boots! — After a _lot_ of comparison shopping (all along Yonge Street, from Bloor to Queen), I finally settled on two pairs of [...]
  • 2004: Strange problem with Linux networking — For some reason, I sporadically have problems with Linux networking, although Windows works without any obvious problems. DHCP works. I acquire a [...]
  • 2004: Nomikai — The nomikai was tons of fun! I’m looking forward to the next one. I met lots of interesting people. Michael Moyle [...]
  • 2004: CHOPSTICKS — “Help me do my hair.” Palsied hands guided mine to the pair of chopsticks Mama always used to bind her hair [...]
  • 2004: Foo — E-Mail%20from%20Jose%20Quesada
  • 2003: D-Link 650 — http://www.linuxhardware.org/features/01/05/14/1121248.shtml
  • 2003: Meeting with Dr. Sarmenta re CS21B — start: 3:30 - Good design - Object-oriented principles - Files - Networking - Threads - Patterns: abstracting and applying to a different situation - Tokenizing strings UML J2ME official patterns [...]
  • 2003: An insight on project defenses — I find that I approach project defenses as my opportunity to learn from the group the insights they had while working [...]
  • 2003: Notes on the CS123 designs — Filed.
  • 2003: Chocolate jewelry — From Martin: http://www.jcreport.com/archive/issue23/index.html check out the first article. The pic of the ring enlarges. Question is, would you wear it or eat [...]
  • 2003: Teaching quote — Teaching quote: “The teacher is the needle and the disciple is the thread.” (Miyamoto Musashi)

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!