WebDriver integration with Jenkins

August 27, 2013 10 comments

WebDriver integration with Jenkins using Maven build tool.

Preconditions :

1. Jenkins should be up and running – http://jenkins-ci.org/

2. Java and Maven should be installed

Through this post, I am trying to say how you can easily integrate WebDriver tests[Java] on Jenkins using Maven build tool.

  1. First Things First – Run Tests on Local First
  • Folder Structure

Create folder structure like below







  • pom.xml

pom.xml file is the basic building block of Maven. Here is a sample pom.xml file for a webdriver test that uses Webdriver latest version and Junit 4.11 version.

<?xml version=”1.0″ encoding=”UTF-8″?>

  • Selenium Scripts

Put your selenium scripts in Java folder [/ProjectName/src/test/java]

  • Run Tests from Terminal

Open Terminal and navigate to Project path [cd /Users/anoop/ProjectName]

type ‘mvn test’ and enter

Now you can see your tests are running and you can see results after tests finishes.

Running wpTrialTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.261 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ————————————————————————
[INFO] ————————————————————————
[INFO] Total time: 17.855s
[INFO] Finished at: Tue Aug 27 13:11:00 EDT 2013
[INFO] Final Memory: 7M/134M
[INFO] ————————————————————————

  1. Integrate with Jenkins

Tests are running fine on local machine using maven build now so its time to move those tests to a continuous integration server.

  • Create a “Build a free-style software project Jenkin Job.
  • Configure newly created job.
  • You can mention your source code using any available version management system[Git, SVN, CVS etc]
  • Also you can run Jenkin job against your local directory.
  • Select ‘Invoke Top-Level Maven-targets’ from Build dropdown box.
  • Enter ‘test’ as Goals
  • Save the configuration.
  • Run the Job


To setup a local working copy as source, you have to run the jenkin Job first without mentioning any source and that build will fail because there is no sources in Jenkins workspace. After first build Jenkin will create a work space for current Job. You can identify that path by checking Jenkins Job Console output. Copy all you data under your project directory to Jenkins workspace and run the Job again. Now you can see tests are running.


This post is only for beginners those who trying to integrate webdriver with Jenkins. There are lot of plugins available on Maven so you can customize you build process as you required.


Selenium server Arguments.

July 4, 2011 2 comments

Following are the arguments we can use while starting Selenium Server. If we use these arguments properly we can reduce the amount of time spent for finding a solution for complex scenarios.

port <nnnn>: the port number the selenium server should use
(default 4444)

timeout <nnnn>: an integer number of seconds before we should give up

interactive: puts you into interactive mode.  See the tutorial for more details

singleWindow: puts you into a mode where the test web site executes in a frame. This mode should only be selected if the application under test does not use frames.

profilesLocation: Specifies the directory that holds the profiles that java clients can use to start up selenium.  Currently  supported for Firefox only.

forcedBrowserMode <browser>: sets the browser mode to a single  argument (e.g. “*iexplore”) for all sessions, no matter what is passed to getNewBrowserSession

forcedBrowserModeRestOfLine <browser>: sets the browser mode to all the remaining tokens on the line (e.g. “*custom /some/random/place/iexplore.exe”) for all sessions, no matter what is passed to getNewBrowserSession

userExtensions <file>: indicates a JavaScript file that will be loaded into selenium

browserSessionReuse: stops re-initialization and spawning of the browser between tests

avoidProxy: By default, we proxy every browser request; set this flag to make the browser use our proxy only for URLs containing ‘/selenium-server’

firefoxProfileTemplate <dir>: normally, we generate a fresh empty Firefox profile every time we launch.  You can specify a director to make us copy your profile directory instead.

debug: puts you into debug mode, with more trace information anddiagnostics on the console

browserSideLog: enables logging on the browser side; logging messages will be transmitted to the server.  This can affect performance.

ensureCleanSession: If the browser does not have user profiles, make sure every new session has no artifacts from previous  sessions.  For example, enabling this option will cause all user cookies to be archived before launching IE, and restored after IE is closed.

trustAllSSLCertificates: Forces the Selenium proxy to trust all  SSL certificates.  This doesn’t work in browsers that don’t use the  Selenium proxy.

log <logFileName>: writes lots of debug information out to a log  file

htmlSuite <browser> <startURL> <suiteFile> <resultFile>: Run a single HTML Selenese (Selenium Core) suite and then exit immediately, using the specified browser (e.g. “*firefox”) on the specified URL (e.g. “http://www.google.com&#8221;).  You need to specify the absolute path to the HTML test suite as well as the path to the HTML results file we’ll generate.

proxyInjectionMode: puts you into proxy injection mode, a mode  where the selenium server acts as a proxy server for all content going to the test application.  Under this mode, multiple domains can be visited, and the following additional flags are supported:

dontInjectRegex <regex>: an optional regular expression that proxy injection mode can use to know when to bypss injection

userJsInjection <file>: specifies a JavaScript file which will then be injected into all pages

userContentTransformation <regex> <replacement>: a regular  expression which is matched against all test HTML content; the  second is a string which will replace matches.  These flags can be used any number of times.  A simple example of how this could be useful: if you add “-userContentTransformation https http” then all “https” strings in the HTML of the test application will be changed to be “http”.

SetUp method for Selenium RC.

June 29, 2011 1 comment

We can write setup method for Selenium RC in different ways.

1. Initialize the selenium server for test classes after starting the selenium server manually.

2. Initialize and Start selenium server from the code itself.

If we use TestNG framework we can write this setup method as BeforeClass.

Sample code for first method

    public void testsetUp() throws Exception
        selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, BaseUrl);

Sample code for second method


public void SetUp(String url, String browser) throws Exception
         SeleniumServer seleniumserver = new SeleniumServer();
        setUp(url, browser);

How to configure selenium scripts through Hudson.

May 24, 2011 1 comment

Through this post, I am trying to explain  ‘How to configure Selenium tests in Hudson’. We all know about Selenium and Hudson, these are two well know open source tools. And Hudson is very much helpful for building the selenium scripts in a scheduled manner hence Selenium will take more time to execute tests if suite contains more tests.

Before moving to configuration part we need to create a build.xml file for building the selenium scripts using Ant build. Because I am going to use Ant process to Invoke build.

Preconditions :

Selenium test cases should be able to run through Ant build.

Hudson Setup:

First of all, we need to install Hudson in our system. Its a straight forward and easy step. You can find that in http://wiki.hudson-ci.org/display/HUDSON/Installing+Hudson. After the installation hudson should be up in http://localhost:8080.

Configure the Hudson Jobs for building Selenium scripts:

Now we need to configure selenium Junit test cases in Hudson, for that follow below steps.

1. Click on ‘New Job’ link in the side panel.

2. Enter Job name[say DemoProject]

3. Select ‘Build a free-style software project’ and click on OK button. 

4. You can configure your build in different ways.

  • Build the code from your machine
  • From any of the Source Code Management’ system like CVS, SVN, GIT etc

5. Steps to build test cases from your local machine

5.1 Click on Advanced button under ‘Advanced Project Options’

5.2 Check ‘Use custom workspace’ check box.

5.3 Enter you path where test cases located.

6. Steps to build test cases from any of the ‘Source Code Management’ system like CVS, SVN, GIT [In this step, we don’t want use ‘custom workspace’ as explained above]

6.1 Select any of the system under Source Code Management’ system [say Subversion]

6.2 Enter ‘Repository URL’

6.3 Keep ‘Local module directory’ as .

7. We can configure build time also in Hudson using ‘Build Triggers‘. Currently following build triggers are available

  • Build after other projects are built
  • Poll SCM
  • Build Periodically[generally used one and using syntax of cron]

8. Now, we need to tell Hudson about how do we need to Build the test cases. For that we can use any methods in ‘Add Build Steps’ under ‘Build’ section. We can use either of

  • Execute Windows batch command
  • Invoke Ant
  • Execute Shell
  • Invoke top-level Maven targets.

9. Here I am going to use ‘Invoke Ant’  option and select it from the list.

10. Specify the target name in the ‘Targets’ field.

11. So you finished all the steps for build test cases. Now we need to show the results for that you need to check ‘Publish JUnit test result report’ check box.

12. Enter the path where your reports generates.

13. Click on ‘Save’ button.

Ohh now you are ready for your first Build.

14. Click on ‘Build Now’ button and wait for the build to finish.

You can see the terminal output by clicking ‘Console Output’ link [in corresponding Build page].

Hope it will help you to configure selenium test cases through Hudson.

Categories: Hudson, Selenium

How to stop selenium Grid from Ant build?

March 18, 2011 8 comments

How to stop selenium Grid from Ant build?

This is also a very simple process as similar to starting the Selenium Grrid from a bat/sh file[mentioned here].

First of all we need to create a bat/file with either of following commands

curl -d action=shutdown http://localhost:4444/lifecycle-manager

wget --post-data action=shutdown action=shutdown http://localhost:4444/lifecycle-manager

Save the bat file in the Selenium Grid base directory. Double check bat file whether its working fine by double clicking on that[pre condition : Selenium Hub and RCs must started before].

I am using this way because there is no default ant target for shutting down the Selenium Grid.

Coming to Ant Build, we need to create a custom ant target in build.xml to execute the above bat file. It look like

<target name=”stopGrid”>
<exec dir=”${grid.dir}” executable=”cmd” os=”Windows XP”>
<arg line=”/c stopGrid.bat”/>

Save the build.xml and execute target as ‘ant stopGrid‘.

Happy testing…

How to start Selenium Grid hub and RCs with one click.

March 18, 2011 2 comments

How to start Selenium Grid hub and RCs with one click.

Its a so simple process. We can done it by creating a bat/sh file.  Here is the steps

Open a notepad and enter following

start /B ant launch-hub
start /B ant -Denvironment=”*firefox” -Dport=5555  -DhubURL=http://localhost:4444 launch-remote-control
start /B ant -Denvironment=”*iehta” -Dport=5557  -DhubURL=http://localhost:4444 launch-remote-control

Save the notepad as bat file in Selenium Grid base directory.  Double click on the bat file and it will start Hub and RCs.

Categories: Selenium, Selenium Grid

Selenium IDE basics.

February 11, 2011 Leave a comment

Selenium IDE

As I mentioned in the earlier post, Selenium IDE is a FireFox plug in. It very easy to install and use. I am going to describe how to install Selenium IDE

Installation Steps :

1. Open Firefox.

2. Visit http://seleniumhq.org/download/

3. Click on download link.

4. Browse ask to ‘Allow’ the site to install. Click on Allow button at the top right corner of the browser.

5. Now you can see ‘Software Installation’ pop over and click on ‘Install’ button in that.

6. After the Installation[with in seconds] firefox ask you to restart the browser.

7. After restarting the browser ‘Selenium IDE’ get installed in the browser.

8. You can find the Installed Selenium IDE under tools menu in the browser.

%d bloggers like this: