'Integration testing' (sometimes called Integration and Testing, abbreviated I&T) is the activity of software testing in which individual software modules are combined and tested as a group. It occurs after unit testing and before system testing. Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests defined in an integration test plan to those aggregates, and delivers as its output the integrated system ready for system testing. [WikiPedia]


I will put Selenium to that JOB. Selenium will allow me to run a set of unit test against a running instance of my application and get a feedback on the quality before delivering the software to a testing team.

Making any Maven module Selenium enable is really easy, all you have to do is to add to the dependencies section the following


Now you should be able to cut and paste any test cases developed with Selenium IDE into /src/test/java/

Selenium IDE is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser or export to may different languages: Ruby, Python, Java, PHP, Perl, .Net, JavaScript to name a few. [Learn more]

The java code is in no way different than regular JUNIT test cases, except that it does not use the latest JUNIT 4.x annotations. You’ll be able to run tests like before (right click Run As Junit)

package com.waltercedric.maven;

import com.thoughtworks.selenium.SeleneseTestCase; 

public class TestHello extends SeleneseTestCase {

  public void setUp() throws Exception {
    setUp(http://localhost/helloworld, "*iexplore");

  public void testNew() throws Exception {
verifyTrue(selenium.isTextPresent("Are you an existing Customer")); } }

Some explanations are needed:

  • http://localhost/helloworld is the URL of my tomcat container where my web applications will be deployed (port 80)
  • I choose internet explorer as browser as it is nearly always available on any windows pc, Firefox is not far away, use “*firefox” and  firefox.exe has to be in the environment PATH.
  • The Code above assume that a selenium RC server is running at localhost on port 4444, I will show you how to start one later in this post.

Some remarks about the code above

You will have to somehow make your own Selenium framework out of the generated code, for obvious reasons,

  • You’ll have soon to support many browser "*iexplore", "*firefox", "*opera" and as such use environment variables or configuration files. I recommend you in that case to use Selenium Grid instead of Selenium RC.
  • You can not let the URL and port of the container fix coded http://localhost/helloworld, this URL may change if you target different runtime. 
  • You may want to reuse some part of the generated code multiple times, in different unit test, (like login/logout stuff), java inheritance, interface, and patterns may arrive sooner or later, even if this is unit test code.

Selenium test cases or integration tests are meant to be run in phase “integration-test” against a running instance of your application. That is why don’t forget to deploy your application with Maven cargo or run it inside Jetty in Maven phase “pre-integration-test”

How to use Surefire to run JUnit test in phase “test” and integration tests in phase “integration-test”

The response is by carefully configuring Surefire and naming your Java packages. The pom.xml below show this trick

In phase test, test cases with a word integration or selenium are omitted, while in phase “integration-test” they are run.

        <argLine> -Xmx512m -DuseSystemClassLoader=true</argLine>

Now it is time to start a selenium server locally or remotely so we can start our newly defined test cases.

Selenium Remote control

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.


You can either start a selenium RC server

  • Outside Eclipse, like any java process,
  • Inside Eclipse with a java launcher,
  • Inside Eclipse with Maven and a java launcher.
  • Inside any Maven Phase thank to a plugin XXXXXXXXXXXXX

I recommend you to install Selenium RC in a dedicated VM (VMWare, Virtual desktop, XEN) and to make it team or enterprise wide. I would always recommend to put Linux at work for such a task, unfortunately Internet Explorer is not running at all on Mac nor Linux.. I recommend you this way to run a shared Selenium server in your infrastructure that can be later access by many continuous build agents.

Selenium RC is a Java process requiring only 2 jar to properly start, Download and unpack to c:\selenium-server-1.0-beta-2




Create following in a batch file start.bat, normally all you have to do is to change the first 3 lines

set JAVA_HOME=c:\jdk1.6
set FIREFOX_HOME=C:\tools\Firefox3
set SELENIUM_RC_HOME=c:/selenium-server-1.0-beta-2

set CLASSPATH=%CLASSPATH%;%SELENIUM_RC_HOME%/selenium-server.jar;%SELENIUM_RC_HOME%/selenium-server-coreless.jar 
%JAVA_HOME%/bin/java -jar %SELENIUM_RC_HOME%/selenium-server.jar 

If everything run properly, you should see an ugly DOS windows like the one below


Pointing the browser to http://localhost:4444 will return an error 403, which is no sign of malfunction, currently Selenium RC has no web GUI.



Start Selenium RC server inside Eclipse

If you decide to run selenium RC inside Eclipse, you’ll be mainly benefit from:

  • Project sharing and versioning in CVS/SVN,
  • Command line parameters that will start Selenium RC can also be shared,

Selenium Server in a Maven project/module

Create a new Maven Project named “SeleniumServer” and copy into its pom.xml the following

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Create a Java launcher and use org.openqa.selenium.server.SeleniumServer as main class. If you start the launcher, you will see the following in eclipse console



Selenium RC is now waiting on port 4444 for Selenium Test case orders.

You can now run your test case in eclipse like any other test case using Eclipse build in Junit runner.

comments powered by Disqus

You might like also

Fetching artifact programmatically through REST/API in Nexus 3.x
There is so many case where it is desirable to pull down artifact from Sonatype Nexus using REST API, unfortunately Nexus 3.x Rest API are still under development... Some use cases in Nexus 2.x: You have a script that uses REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them. You make extensive use of the REST API in all your puppet modules You use the Atlassian Puppet module for Nexus for creating repository, …
726 Days ago
When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically :-) You may want to read more first these 2 short articles Update Maven pom version on GIT checkout in TeamCity maven-release-plugin with GIT git-branch-renamer-maven-plugin …
738 Days ago
Review: Getting Started with Apache Maven by Russell Gold
Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was "Getting Started with Apache Maven" http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache Maven. The course is organized in eight chapters, forty videos with a length between two …
1925 Days ago
Update Maven pom version on GIT checkout in TeamCity
Here is a solution to the following problems Deriving Maven artifact version from GIT branch, Update pom version on GIT checkout automatically, Add the ability to use Pull request with Apache Maven. You have a workflow requirement that require you to have the artifact version of a module externally defined from the current branch in GIT. For example You want to start working on a new feature branch “feature-memory-improvement”, so you branch from master a new branch named feature/feature-memory-improvement Having …
1930 Days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, improving network efficiencies and application load time in certain case. If you are not using Apache with mod_deflate or nginx in front of your web application, you may need to implement resources compression yourself…. Wait! don’t start writing your own filter to compress files like CSS, html, txt, javascript it is way more difficult than you think to properly handle http response headers and …
2412 Days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A typical scenario would be to start a servlet container prior to running integration tests (Selenium, SAHI or using any other framework you can think of ) With the following examples, you will be able to start an instance of Tomcat 7 running your web application in the pre-integration-test phase and stop the instance in the post-integration-test phase. You can also decide to …
2412 Days ago
Apache Maven copy local file to a remote server server using SSH
I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed. Solution with Ant SCP task This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can …
2600 Days ago
Apache M2Eclipse: Get rid of Duplicate resources when opening resources and types
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view of Eclipse Eclipse – M2Eclipse – Subversive …
2606 Days ago
Apache Maven 3 Cookbook
&160; First a big thanks to Packt Publishing for having sent me this book to review! I did enjoy going through this book, while I did not learn a lot of new stuff (I am using Apache Maven daily since 2006!), I found it to be concise and would recommend it anytime to any of my colleagues. But let’s go through my review of this cookbook of over 50 recipes towards optimal Java Software Engineering with Maven 3: Apache Maven
2748 Days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days Grasp the fundamentals and extend Apache Maven 3 to meet your needs Implement engineering practices in your application development process with Apache Maven Collaboration techniques for Agile teams with Apache Maven Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven You …
2794 Days ago