In my previous post, I explained how to run the Selenium test suite on a Ubuntu server. Now, let’s suppose you have Hudson (software for Continuous Integration) installed in your server and you want to create a job that executes a Selenium Test suite. I am going to show you how to do this in the following sections.
I will assume Hudson is already installed and running in your build server and also that you have a HTML test suite. In case you don’t have a test suite, check this post: how to create a Test Suite in Selenium?
Install Hudson Seleniumhq Plugin
Hudson Selenium Plugin will allow you execute a Selenium HTML test suite as a Hudson job.
To install the plugin, follow these steps:
1. In Hudson Home, go to “Manage Hudson”.
2. Click on “Manage Plugins”.
3. Click on “Available”.
4. Look for “Hudson Seleniumhq Plugin” and click on the checkbox.
5. At the end of the page, click on Install.
You need to configure Hudson, so that it knows where the Selenium Remote Control is and also which X server to use when running Firefox.
In my previous post, I showed you how to install Selenium RC and configure xvfb to make it use a specific display.
To configure Hudson, follow these steps:
1. Go to Hudson Home.
2. Go to “Manage Hudson”.
3. Click on “Configure System”.
4. In “Global properties”: click on “Add”.
5. Enter “DISPLAY” as name and “:7.0” as value. ( You can enter the display you are using, in my case is 7)
6. Go down to “Selenium Remote Control”; in htmlSuiteRunner enter the location of Selenium Remote control.
7. Click on “Save”.
Create the job that runs the HTML Suite
You basically need to create a job that includes a “SeleniumHQ htmlSuite Run” step.
1. Go to Hudson Home.
2. Click on “New Job”.
3. Enter a value for “Job Name”.
4. Select a Job type: “Build multi-configuration project (alpha)”.
5. Click on “Ok”.
6. In “Build”, click on “Add build step”.
7. Select “SeleniumHQ htmlSuite Run”.
8. Enter the variables :
Browser: the browser that will run the test suite. For example: *firefox
startURL: start URL . For example: “http://www.google.com”
suiteFile: suite file location. For example: [location]/TestSuite.html
resultFile: HTML result file location. For example: [location]/TestResults.html
In this example I also added an extra step to take a screenshot of the X-server after running the test suite; this could be useful for debugging. For this step, you can use the tools showed in my previous post: xwd and ImageMagick.
1. In “Build”, click on “Add build step”.
2. Select “Execute shell”. (“Execute Shell” is for Linux, you can use “Execute batch” for Windows).
3. Add these commands:
(“firefox_results” will be the dump file)
xwd -root -display :7.0 -out /home/oshyn/projects/selenium/firefox_results
convert /home/oshyn/projects/selenium/firefox_results /home/oshyn/projects/selenium/firefox_results.jpg
Execute the job that runs the HTML Suite
1. Go to Hudson Home.
2. In Jobs dashboard, click on “Schedule a build” button for the just created job.
The job will start running; see “Build Executor Status” at the left side.
In Jobs dashboard, you can see the last success, last failure and last duration of your job.
Check the console output of the Hudson job
To see if your job really runs, check the Console output of your job:
1. Click on your job name.
2. Below “Configurations”, click on “default”.
3. In “Permalinks”, click on last build.
4. Click on “Console Output”.
Building on master
[default] $ java -jar /home/oshyn/selenium-server-1.0.3/selenium-server.jar -htmlSuite *firefox http://www.google.com /home/oshyn/projects/selenium/TestSuite.html /home/oshyn/projects/selenium/TestResults.html
17:18:07.602 INFO - Java: Sun Microsystems Inc. 10.0-b23
17:18:07.604 INFO - OS: Linux 2.6.24-19-server i386
17:18:07.611 INFO - v2.0 [a2], with Core v2.0 [a2]
17:18:07.711 INFO - RemoteWebDriver instances should connect to:
17:18:07.712 INFO - Version Jetty/5.1.x
17:18:07.713 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
17:18:07.714 INFO - Started HttpContext[/selenium-server,/selenium-server]
17:18:07.716 INFO - Started HttpContext[/,/]
17:18:07.730 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@17590db
17:18:07.730 INFO - Started HttpContext[/wd,/wd]
17:18:07.733 INFO - Started SocketListener on 0.0.0.0:4444
17:18:07.734 INFO - Started org.openqa.jetty.jetty.Server@1af9e22
17:18:07.844 INFO - Preparing Firefox profile...
17:18:42.848 INFO - Launching Firefox...
17:19:00.710 INFO - Checking Resource aliases
17:19:06.039 INFO - Checking Resource aliases
17:19:06.040 INFO - Received posted results
17:19:06.452 INFO - Killing Firefox...
17:19:16.456 INFO - Process didn't die after 10 seconds
17:19:16.558 INFO - Shutting down...
17:19:16.559 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
[default] $ /bin/sh -xe /opt/tomcat/apache-tomcat-6.0.20/temp/hudson8503.sh
+ xwd -root -display :7.0 -out /home/oshyn/projects/selenium/firefox_results
+ convert /home/oshyn/projects/selenium/firefox_results /home/oshyn/projects/selenium/firefox_results.png
I did not get the error: “Error: no display specified …. HTML suite exception seen”, as I previously configured the DISPLAY variable.
Check the HTML file results and final screenshot
Also, you can copy the results HTML file and the screenshot from an Ubuntu build server to your Windows machine, using WinSCP.
If you want to see the HTML results file and final screenshot from Hudson, you can copy these files to the Hudson Job workspace; just add these lines to the “Execute shell” step:
cp -f /home/oshyn/projects/selenium/TestResults.html [hudson location]/jobs/seleniumHTMLTest/workspace/default
cp -f /home/oshyn/projects/selenium/firefox_results.jpg [hudson location]/jobs/seleniumHTMLTest/workspace/default
In this case, you can open the results file directly from Hudson.