Tuesday, September 3, 2013

Jenkins: Static Analysis with CheckStyle

In the last post I mention how to configure your Maven Webdriver project on Jenkins, today let's see how to configure checkStyle plugin for static analysis with jenkins.

Configure Check Style with Maven

Mention the following plugin in pom.xml, make sure you mention it inside build block 


Configure Check Style with Jenkins
follow the steps mention below to configure and generate checkStyle Report in jenkins
Install checkStyle plugin Navigate to Manage Jenkins->Manage Plugin and install checkStyle plugin and then restart the jenkins 

Configure checkStyle for project
 Following is how to configure checkStyle for Maven project, it might vary if you are using ANT. 
  • Append checkstyle:checkstyle to your build goal
  • check Publish Checkstyle analysis results
    Configure Checkstyle for project
    Configure checkStyle for Project
Configure checkStyle Reports
 Now you need to configure which reports you want to see for this project, follow the steps to configure reports
  • Navigate to Jenkins home page and create new view
    Add New Dashboard for checkStyle
    Add new dashboard for checkstyle
  • Select the project you want to include for checkStyle Report
    Add Projects for checkStyle Report
    choose jenkins jobs for checkstyle
  • Include the graphs/reports you want
    Select Graphs for checkStyle report
    configure checkstyle report in jenkins

Monday, September 2, 2013

WebDriver with Jenkins

In the last post we see how to create Maven Project for WebDriver from eclipse. Now let's configure same Webdriver Maven Project on Jenkins.

Setup Jenkins on Windows 

download the jenkins from following location
Running Jenkins as War file 
You can run jenkins using war file, if you are doing it you don't need any slave to start on machine. Running Jenkins as Windows Service 
If you have installed Jenkins as Windows Services then you need to Start Slave and Bind you project to that slave.

Create/Run Slave Node 

If Jenkins is installed as Windows Services you need to start the JNLP slave node on machine where you need to execute your test cases. Follow the process to create node.
  • Go to Manage Jenkins->Manage Nodes and Click on New Node
  • Enter the Node Name and choose Dumb Slave
    Create Jenkins Slave node for WebDriver Execution
    Create Jenkins Slave node for WebDriver Execution

  • Enter the information as mention in the screenshot
    Configure Node for WebDriver
    Configure Node for WebDriver
  • After saving node will be listed under Nodes 
    All Available Nodes in Jenkins
    All Available Nodes in Jenkins
  • Start the node by Running displayed command in CMD
    Start JNLP node in Jenkins
    Starting JNLP Node in Jenkins
  • if everything has been done correctly if you will able to see small java program running
    Connected JNLP Node
    Connected JNLP Node

Configure Maven in Jenkins

Before you create a new Job for Maven WebDriver Project, let's configure Maven in jenkins
Go to Manage Jenkins->Configure System and Provide Installation directory for JDK and Maven as mention in screenshot below
Configure JDK and Maven in Jenkins
Configure JDK and Maven in Jenkins

Create New Job on Jenkins

Now let's create the new Job for Project
  • Go to Home page and click on New Job
    Create Jenkins Job for Maven WebDriver Project
    Create Jenkins Job for Maven WebDriver Project
  • Restrict the job to run on the Slave Node we created
    Configure WebDriver Project to run on Specific Node
    Configure WebDriver Project to run on Specific Node
  • Click on Use custom workspace and Mention your workspace location und Directory
  • Provide the path of pom.xml in Root POM and provide Test in Goals and Options
    Provide Maven in Goal in Jenkins
    Provide Maven Goal in Jenkins

Sunday, September 1, 2013

WebDriver with Maven

Maven is a build Automation Tool somewhat like ANT. Having use ANT for the previous project wanted to try Maven this time. I thought it would be easy as I know ANT, however it took a while for me to figure out as i didn't find any proper tutorial on net. And this is the reason I am writing new Blogpost.

I have just started, So if someone knows the better way to do few things mention here please let me know in comment.

Now let's try setting up new Maven Project for Webdriver using Eclipse. However before you do, you need to download and setup Maven on you local machine.

Setup up Maven
  • download the appropriate maven from the following site.
    http://maven.apache.org/download.cgi Extract it to some location and setup the PATH variable. 
  • If you have done everything correctly, Following command on CMD will let you know the Maven Version.
    mvn --version 

Install Maven Plug-in in Eclipse 
Install the m2Eclipse plugin in you eclipse

Setup Maven Project for WebDriver.

  • In Eclipse choose New Maven Project and check the "Create Simple Project" 
  • Fill the Group id and Artifact id 
  • Create New Class named "GoogleTest" under "src/test/java" Copy Following code in it.
  • GoogleTest.java 

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.Test;
     * @author Gaurang_Shah
    public class GoogleTest {
     private WebDriver driver;
     public void verifySearch() {
      driver = new FirefoxDriver();

  • It will show you some compile time error as we haven't added the dependencies yet.
  • Maven mention all the dependencies in pom.xml file. Please copy and replace the following pom.xml with your project pom.xml file.
    <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/xsd/maven-4.0.0.xsd">
  • Running Project
    • To run from Eclipse, Right click on pom.xml and choose Run as --> Maven Test 
    • To run from command line, Go to project directory and enter following command
       mvn test