Archive

Posts Tagged ‘Maven’

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

ProjectName

pom.xml

src

test

java

YourTest.java

  • 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″?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>anoop.philip</groupId>
<artifactId>web-driver-jenkins-integration</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>

  • 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.

——————————————————-
T E S T S
——————————————————-
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] BUILD SUCCESS
[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

Image

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.

P.S

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.

Advertisements
%d bloggers like this: