Setting up automated Selenium testing with Jenkins/Hudson

Please note: This article is old and refers to Selenium Server which has been deprecated by Selenium Webdriver so the following post is now pretty useless!

There's a big thing about unit testing at the moment, well, unit testing is something that's been around for years, and no doubt it's something that the best companies have been doing for a long time. There can be quite an overhead in setting up testing, especially unit testing, because it can require a test environment as well as the tests themselves. In the longer term, code is more stable, better managed, and you can be a lot more confident when deploying.

I've always been one for getting the best return on effort which is why I particularly like Selenium. There is the Firefox plugin for Selenium where you can record your tests directly from your browser, export them to your code base, commit them and then Jenkins will run them for you!

Without repeating stuff and giving credit where it's due I followed the blog here: http://www.labelmedia.co.uk/blog/posts/setting-up-selenium-server-on-a-h...

That got me most of the way but unfortunately, because I didn't understand all of the configuration lines it just didn't work. So hopefully, I can explain them now and help you set your own one up.

In the execute shell step we have this:

export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar
-browserSessionReuse -htmlSuite *firefox http://path/to/app
/var/lib/jenkins/jobs/project/workspace/path/to/Suite.html
/var/lib/jenkins/jobs/project/workspace/path/to/logs/selenium.html

This must be all on one line, that may not be completely true, but if you test the command from the terminal, then it must be all on one line because they are parameters for the selenium-server.jar program.

http://path/to/app
This is the web address of the site you are testing. The server doing the testing will need to access it so you should test it by curling it. I had the site running on the same server doing the tests so I also needed to check the vhost was set up correctly and the site was working.
/var/lib/jenkins/jobs/project/workspace/path/to/Suite.html
I originally thought this was the filepath to the web root, I have no idea why I thought that now. It is the path to the Selenium test suite. You need to export your test suite from the Selenium IDE by doing: File > Export Test Suite As... > HTML. Note, there is also the option to 'Export Test Case'. I may have done and in fact it didn't work until I had both a test suite file and a test case file. e.g. testlogin.html which tested logging in, and testsuite.html which just pretty much specified testlogin.html. Both are readable HTML table structures. These need to be uploaded to the server to the path above and of course the full path calls the test suite rather than the test case.
/var/lib/jenkins/jobs/project/workspace/path/to/logs/selenium.html
This is a log file which I had to create and make sure was writeable by Jenkins.

If you're still having problems running Selenium through Jenkins then take the full command and run it through terminal. It should give you some useful errors and you can also add the -debug flag after selenium-server.jar.

Once it's all done, you'll have a link in Jenkins to the most recent selenium report on the project page and of course the build will fail if the Selenium tests fail.

Post new comment

By submitting this form, you accept the Mollom privacy policy.

User login

Author of...

  • My blog about 'Time is NOT money'... and value http://t.co/g2C6pZy0 12 years 7 weeks ago
  • I've found an excellent query logging and filtering module for Drupal. Not available via http://t.co/U1Xe92Th: http://t.co/2qvg1DgE 12 years 11 weeks ago
  • I've just spotted my first © 2011 at the bottom of a website. 12 years 11 weeks ago
  • @da_lune That's the spirit, oh, too late @gavinbrook, Wordpress is fantastic & now more than a blogging tool but Drupal = more functionality 12 years 15 weeks ago
  • @oliverpolden is having an amazing day for many reasons. I feel like giving back: http://t.co/JvKVVMBF Have a request? use the contact form. 12 years 15 weeks ago
  • The world's population is 7 billion. If a few 'competing' companies mutually helped each other get more customers business would be easy. 12 years 15 weeks ago
  • @Casablanca Amazing photos! Thank you for sharing. 12 years 16 weeks ago
  • Ahh, the Christmas Snow module for Drupal: http://t.co/QzvkQiT2 12 years 16 weeks ago
Oliver Polden