Thursday, March 13, 2014

Automated Browser Testing using Selenium

I just started using Selenium for automated browser testing. It's turning out to be really nice as a kind of SharePoint site warm up script too. This is what I've got running on my box right now for automated tests on a schedule:

Setting up a Selenium test script to run on a schedule on Windows 7
  1. Create a directory on your local system c:\selenium
  2. Install the seleniumn IDE FireFox plugin for recording/saving tests.
  3. Record a browser test with a starting point of
  4. save the test as c:\selenium\MyGoogleTest.html.
  5. Save the test suite as c:\selenium\MyGoogleTestSuite.html.
  6. Download selenium-server-standalone-2.40.0.jar so you can run test scripts from the command line
  7. copy the selenium-server-standalone-2.40.0.jar to c:\selenium\selenium-server-standalone-2.40.0.jar
  8. create a bat file to run your test script command c:\selenium\RunMyGoogleTest.bat
  9. Edit the bat file and paste in this command:
    java -jar selenium-server-standalone-2.40.0.jar -htmlSuite "*firefox" "" "c:\selenium\MyGoogleTestSuite.html" "c:\Selenium\results.html"
  10. Open a command prompt, change the current directory to c:\selenium and run RunMyGoogleTest.bat. Firefox should launch and show your tests being performed.
  11. Create a new windows scheduled task. In the action tab, add a new action.
    • Action: Start a program
    • Program/Script: C:\Selenium\RunMyGoogleTest.bat
    • Start in (optional): c:\Selenium
  12. You can setup the task to run as any user that's ever logged onto your computer. So if you dont want to see windows opening every time the task runs, change the user the task runs as something other than your user account.
  13. Run the scheduled task by hand to confirm it works. Again, it should launch firefox and run your tests.
Tests fail because they run too fast. How do I force a slow test run?

You can force selenium to run the test slower by hacking up the test suite html. After the open command you can add setSpeed command that will force every clickAndWait method to pause before running the next command, giving the browser time to load page content. For more info -


John Mathews said...

Excellent post!!! Selenium automation testing tool makes your software validation process lot simpler. Keep on updating your blog with such awesome information. Selenium Course in Chennai

jackpeppin said...

woow nice explanation about selenium. we are also taking selenium training in chennai. please visited us Selenium Training in Chennai | Selenium Training in Bangalore

henrystaples said...

Great; thanks for the post. Made it super-quick to get setup. I had been putting off using the .jar file for a while.