This article will provide more detail about integrating Selenium into your ContinuousIntegration engine. The example will be based on CruiseControl.Net and Nant but can easily be ported to regular CruiseControl and Ant. I assume that you are familiar with Continuous Integration, Nant and Selenium.
To achieve Continuous Integration (CI) with selenium you need to achieve the following steps
- Selenium needs to run automatically, and save its results to file
- Nant script needs to call selenium
- Nant needs to wait for the results
- Nant needs to react to those results (i.e. should we fail on errors)
To have Selenium run automatically, simply add auto=true to the command line. To record the results of a test run, also add resultsUrl=tests\HandleResults.php.
For example:
The content of HandleResults.php is outlined below:
The above task will simply write the results of the test run to file. The resulting XML looks simliar to:
Now that we can record the results of a Selenium test run to file, we need Nant to be able to call that URL above, and react to the results as necessary. The task would look similar to:
Please refer to the resources at the end of this article for the source code to the selenium task above. Please note that I have not shared this directly with Nant or NantContrib. Key features of this task include:
- Specify which browser (browserExe) you care about (e.x.: IE versus FireFox, ...)
- Specify the suitesuite (testSuiteUrl) to execute your tests
- Specify how long to wait (maximumWaitTimeInSeconds) to avoid infinite waiting
- Specify if you care about errors or not (failonerror)
There is a lot more to consider to get a reliable Selenium CI environment working (i.e. configuring a database, visiting the correct website address, etc), but the above will help get your foot in the door to bring automated QA testing a giant step above merely running developer tests.
Additional Resources
Cruise Control for Selenium - http://openqa.org/selenium/testrunner.html
Nant - http://nant.sourceforge.net/
How to write a custom nant task - http://blogs.geekdojo.net/rcase/archive/2005/01/06/5971.aspx
CruiseControl.Net - http://confluence.public.thoughtworks.org/display/CCNET/
Additional Source Code
SeleniumTask.cs
LoggedTask.cs
SeleniumTaskTest.cs
Andrew, I can't compile the task because I don't have NAntHelper or don't know what it is. Am I missing a dll? Is this part of the Nant installation? Cheers.