After attending our local SeleniumCamp (www.seleniumcamp.com) in February this year I found very interesting possibilities for testing web applications. This topic I would like to share my thoughts about how to use Selenium framework to improve test coverage of our drupal sites.
Why do we need anything else when we have simpletest framework?
But demo first!
There are numerous products that you can find on the website of the Selenium (http://seleniumhq.org/).
This is plugin to Firefox that you can record your actions and then "play" them. WIth this plugin you can also do some asserts and then ensure that test runs properly. I believe this is the fastest way to try selenium and make some profit of it.
This is a server (java application) that you can start to run your recorded tests. Scenario is following: download Selenium Server (formerly the Selenium RC Server) from http://seleniumhq.org/download/ and run it (you need to have your java environment ready. "java -jar selenium-server-standalone-2.0b3.jar"). Export your tests recorded with Selenium IDE to PHP format. Install PHPUnit (you can do it via PEAR installer or using "sudo apt-get install phpunit"). There is a lot instructions on internet how to do that. And run your tests
phpunit saved-test.php. Personally I liked this was of recording and executings tests very much as they are very easy to create. Also you can run your tests with Selenium RC from different browsers like chrome, internet explorer.
Best documentation about these tests I found on site of PHPUnit http://www.phpunit.de/manual/3.0/en/selenium.html.
This is most edge technology that joined Selenium lately. The idea is that server communicates with browsers directly via theirs drivers and performs native events with browsers. So the idea is that we completely emulate actions performed by user. Webdriver is joined into Selenium Server so you can follow instructions above to start it. There are no oficial library for communication with Webdriver from PHP. The protocol of communication to webdriver server is described on http://code.google.com/p/selenium/wiki/JsonWireProtocol. I have found two libraries that are opensourced: http://code.google.com/p/php-webdriver-bindings/ and https://github.com/chibimagic/WebDriver-PHP. The second library integrates with PHPUnit. Truly to say I haven't to write tests and run them with PHPUnit but there are asserts there from PHPUnit class.
I can see Selenium testing very interesting technology that can help us to build our websites. It can be used in different ways. First of all it can be very good for testing our modules. Another point is that with Selenium IDE we can create tests very fast and to have some basic test coverage of the functionality that needs a lot of clickwork. In my case I have used Selenium recorded scenario to install custom drupal profile as part of build process for continuous integration. I am sure everyone finds his own way to use this framework as it adds so much possibilities to test our software and make it better!