Thursday, May 7, 2009

Automated testing with Hudson and Selenium

We use Hudson for continuous integration. I prefer Hudson from CruiseControl since its more user-friendly and one can easily add projects through the easy-to-use GUI instead of manually manipulating XML files.

Selenium is great framework to create automated tests.
My purpose was to automate the automated tests and add them to our build process so we have 'full circle'.

I created a little Java project and an ANT script where one can record tests using the Selenium IDE and adds these tests to our test suite. Test results are displayed using TestNG. If anyone is interested I can send him the test project I created.

My only problem was how to get the Selenium Server running when starting the job through Hudson.

My first attempt was an ANT as the following one:
<target name="start-selenium-server">
<java timeout="300000" fork="true" jar="${ws.home}/selenium-server-1.0-beta-2/selenium-server.jar">
<arg line="-port 4444">
<arg line="'-firefoxProfileTemplate">
</arg>
</arg>
</java>
</target>
While this approach worked fine when running through a command window, unfortunately the fork=true didn't work properly when launched as an ANT build step from Hudson. Hudson waited until the process timed out and didn't start the Selenium Server on a separate JVM.

My second attempt was to have the Selenium Service running as a Windows Service. This approach worked great!
I used Java Service Wrapper

One can easily follow the instructions here to set up JSW.

But this is how I have set up the wrapper.conf file:
# Java Application wrapper.java.command=%JAVA_HOME%/bin/java # Java Main class. This class must implement the WrapperListener interface # or guarantee that the WrapperManager class is initialized. Helper # classes are provided to do this for you. See the Integration section # of the documentation for details. wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp # Java Classpath (include wrapper.jar) Add class path elements as # needed starting from 1 wrapper.java.classpath.1=../lib/wrapper.jar wrapper.java.classpath.2=/selenium-server-1.0-beta-2/selenium-server.jar wrapper.java.classpath.3=/selenium-server-1.0-beta-2/selenium-server-coreless.jar wrapper.java.classpath.4=/selenium-server-1.0-beta-2/selenium-server-sources.jar wrapper.java.classpath.5=/selenium-server-1.0-beta-2/selenium-server-tests.jar wrapper.java.classpath.6=/selenium-server-1.0-beta-2/selenium-server-test-sources.jar # Java Library Path (location of Wrapper.DLL or libwrapper.so) wrapper.java.library.path.1=../lib # Java Additional Parameters # Log file to use for wrapper output logging. wrapper.logfile=../logs/wrapper.log wrapper.commandfile=./dump.command wrapper.ntservice.console=true # Initial Java Heap Size (in MB) #wrapper.java.initmemory=3 # Maximum Java Heap Size (in MB) #wrapper.java.maxmemory=64 # Application parameters. Add parameters as needed starting from 1 wrapper.app.parameter.1=org.openqa.selenium.server.SeleniumServer wrapper.app.parameter.2=-port 4444 wrapper.app.parameter.3=-firefoxProfileTemplate "C:\firefoxProfile" #Log Level wrapper.console.loglevel=DEBUG wrapper.logfile.loglevel=DEBUG #******************************************************************** # Wrapper Windows Properties #******************************************************************** # Title to use when running as a console wrapper.console.title=SeleniumService #******************************************************************** # Wrapper Windows NT/2000/XP Service Properties #******************************************************************** # WARNING - Do not modify any of these properties when an application # using this configuration file has been installed as a service. # Please uninstall the service before modifying this section. The # service can then be reinstalled. # Name of the service wrapper.ntservice.name=SeleniumService # Display name of the service wrapper.ntservice.displayname=SeleniumService # Description of the service wrapper.ntservice.description=SeleniumService # Service dependencies. Add dependencies as needed starting from 1 wrapper.ntservice.dependency.1= # Mode in which the service is installed. AUTO_START or DEMAND_START wrapper.ntservice.starttype=AUTO_START # Allow the service to interact with the desktop. wrapper.ntservice.interactive=true

No comments:

Post a Comment