How to get faster Selenium test cases execution

Recently, I went to China to work with the BonitaSoft Quality Assurance (QA) team. We spent some time to improve Selenium execution speed. I will share the QA team knowledge on this, and give two tips. Just by using these two tips, we improved Selenium speed - 5 times fast on IE8 (from 8 hours to 1h30min) and 3 times faster on Firefox3 (from 3 hours to 1 hour). Check it graphically: OK, so here are the tips:

Tip 1: Use the Cybozu library to execute tests on IE

Selenium provides this library. You can find the reference in the documentation:

You need to add few more lines of code. Here is a java snippet:

Selenium selenium = getSelenium(); if(selenium.getEval("navigator.userAgent").contains("IE")){ selenium.useXpathLibrary("javascript-xpath"); }

And why IE but not on Firefox? Simply because Firefox provides a great XPath parser natively.

Tip 2: Use setSpeed carefully

setSpeed allows you to configure a wait time between each execution of a Selenium request. See for yourself in the javadoc: I recommend using waitPageForCondition or waitPageForLoad instead. This way, the Selenium code executes as soon as the page is loaded instead of waiting. So, instead of waiting a pre-defined time, during which the application is doing nothing and the developer just hopes that the required element has loaded completely, the test continues.

Ok, sometimes we found it necessary to use setSpeed. In this case, we changed setSpeed for a (little) part of the code, If you do this, don’t forget to set it back to its default value 0.

We also found that using a higher setSpeed value when debugging might let the developer to see easily what is happening - you might try this. I personally love setSpeed for debug mode.

Do you want more?

So do we. We still have some avenues to explore:
  • Evaluate Selenium Grid (and perhaps also Saucelabs).
  • Move to Selenium 2 and use the new WebDriver API.
  • Open all tests in the same browser (without exceeding its memory) in order to not lose time launching new browsers.
And you? Which tricks are you using? Do you have some suggestions for us? Some feedback from your own tests?

We will be happy to learn from your experience.