Functional Testing with Selenium

Selenium is an open source software used for automating web applications for testing purposes.

Selenium is used for functional tests on Zurmo.

Learn more about Selenium here: http://seleniumhq.org.

Building functional tests for Zurmo

Our experience at engineering functional tests for Zurmo has been a challenging experience.  Not only do different browsers react differently, but also the IDE vs. Command Line runner react differently to some things such as confirmation boxes.  On top of this Selenium can be finicky based on how fast the server response is but also how fast the browser itself is handling the work.  All this coupled together makes it extremely difficult to create functional tests.

Recently we were having some problems with random failures that was making the functional tests basically useless.  I took all day to investigate what was going on and was able to completely refactor all the Accounts tests and also made it so it runs on FAST speed as opposed to slow speed.  Below are some guidelines for writing selenium tests

  • Write all your tests in the FireFox IDE and focus first on getting it running successfully there.
  • Do not worry about Chrome/IE, as the first objective is a stable test suite in FireFox.  It is more important to have it fully stable on one browser than sort-of working in 3 browsers
  • Write all your tests to work on FAST speed.  In the beginning we thought that because selenium was finicky we had to write everything to run on SLOW speed.  This in fact creates problems, so make your test run on FAST speed.  We have found only one spot so far that requires temporarily slowing the speed down for several lines.  I will mention that in a bit.
  • Anytime you are doing an action that causes the entire page to load you need to follow the following pattern:

Pattern for going directly to a url

  • open – myURL
  • waitForPageToLoad
  • waitForCondition – selenium.browserbot.getCurrentWindow().jQuery.active == 0

Pattern for going to a new page via either a javascript event or some link on a page

  • clickAndWait – myButton or selectAndWait on select input, etc.
  • waitForPageToLoad
  • waitForCondition – selenium.browserbot.getCurrentWindow().jQuery.active == 0

Pattern for doing something in AJAX (Do not use AndWait)

  • click – someLinkOrSomeButton
  • waitForCondition - selenium.browserbot.getCurrentWindow().jQuery.active == 0
  • waitForElementPresent or waitForText (xpath)    - Only wait for something NEW coming into the page. Make sure it doesn’t exist in some other form first
  • You should always have a waitFor… after waitForCondition to make sure the ajax fully completed.  Sometimes this is not possible but make sure you try hard to do this.

When dealing with coming to a listview and you want the search to be cleared of any stickiness do this

  • Add ?clearingSearch=1 to the URL.  This is done when you do open myURL and is a nice way to reset a listview for further testing

When dealing with an xPath

  • waitForText works usually.  waitForTextPresent usually does not work.

When trying to wait for something to be there

  • use waitForElement when you don’t care about a value of something just that an element is now present

When dealing with confirmation links

  • the IDE sees them, the java runner does not seem to notice a confirmation link in FAST mode.  So you need to do this
  • setSpeed 2000
  • do your stuff that causes a confirmation box
  • setSpeed 1
  • This will make sure the confirmation is processed properly

 

Leave a Comment