Selenium tests

When we develop code at VG we have started to use Selenium tests for continuous integration. This allows us to easy write tests that programmatically checks that last commit didn’t break anything.

What is Selenium?
You can look at it like a browser that fires of a set of requests that you asks it to. Sort of like this:

  • Go to
  • Check that the title is “Forsiden at VG”


  • Go to
  • Click on the first article
  • Check that the article loads correctly and some elements are present on the page

You can also do more advanced things like triggering a javascript method for show and hide a menu.

  • Go to
  • Click on menu tab
  • Wait for 500 ms
  • Check that the menu is now visible

So let’s start to write some tests. Ehm, okay, we actually don’t have to write it. We can use Selenium IDE, a Firefox plugin; Awesome!

Skjermbilde 2013-05-15 kl. 11.13.39


When the test works okay we can export it to PHP Unit Selenium tests.

Go to File -> Export Test Case As -> PHP (PHPUnit)

This gives you a file like this:

Here is another example for testing that the menu becomes visible and gets populated with sub menu items:

This is what it looks like when you run the IDE
Skjermbilde 2013-05-29 kl. 14.14.24

Selenium is just great and should really be used whenever integrating new features. Properly designed tests can check and verify that existing interactivity and markup still works as intended when new features are introduced.

Finally, to create a really powerful environment, you should set up Jenkins to automatically start a build and run phpunit tests and Selenium tests for each commit. This will save you a lot of time, by automatically be notified when something unintentionally breaks.

Read more from the Software engineering category