Using Jenkins and Maven for Selenium WebDriver test execution in continuous integration

Jenkins supports Maven for building and testing a project in continuous integration. In this recipe, we will set up Jenkins to run tests from a Maven project.

Getting ready

Running tests with Jenkins and Maven needs both the tools installed on the machine. In this recipe, the SeleniumCookbook project is used from the earlier Configuring Eclipse and Maven for Selenium WebDriver test development recipe.

This recipe refers to Subversion as the Source Code Management (SCM) tool for the SeleniumCookbook project.

You can use various SCM tools along with Jenkins. If Jenkins does not support the SCM tool that you are using, please check the Jenkins plugin directory for specific SCM tool plugins.

How to do it...

  1. Navigate to the Jenkins Dashboard (http://localhost:8080 by default) in the browser window.
  2. On Jenkins Dashboard, click on the New Job link to create a CI job.
  3. Enter Selenium Cookbook in the Job name textbox.
  4. Select the Build a maven2/3 project radio button, as shown in the following screenshot:
    How to do it...
  5. Click on OK.
  6. A new job will be created with the specified name.
  7. On the job configuration page, go to the Source Code Management section and select the Subversion radio button.
  8. Enter the URL of your test code in the Repository URL textbox, as shown in the following screenshot. Optionally, Jenkins will ask for the Subversion login details. Provide user credentials as configured on your SVN server:
    How to do it...
  9. Go to the Build section. In the Root POM textbox, enter pom.xml, and in the Goals and options textbox, enter clean test, as shown in the following screenshot:
    How to do it...
  10. On the Selenium Cookbook project page, click on the Build Now link. Go back to Jenkins Dashboard.
  11. Maven builds the project and executes tests from the project. Once the build process has been completed, click on the Selenium Cookbook project from the list, as shown in the following screenshot:
    How to do it...

    The Selenium Cookbook project page displays the build history and links to the results, as shown in the following screenshot:

    How to do it...
  12. Click on the Latest Test Result link to view the test results, as shown in the following screenshot:
    How to do it...

Scheduling build for an automatic execution

  1. Go to the Selenium Cookbook project configuration in Jenkins.
  2. In the Build Triggers section, select the Build periodically checkbox.
  3. Enter 0 22 * * * in the Schedule textbox, as shown in the following screenshot. This will trigger the build process every day at 10 p.m. and the test will run unattended:
    Scheduling build for an automatic execution
  4. Click on the Save button to save the configurations.

How it works...

Using the Build a Maven2/3 Project option, Jenkins supports building and testing Maven projects.

Jenkins supports various SCM tools such as CVS and Subversion. To get the source code from SCM, specify the repository location and check out the strategy. Since Maven is used in this example, specify the path of root POM and Maven Goal.

While building the project, Jenkins gets the latest source from SCM to the Jenkins project workspace. It will then call Maven with specified goals. When the build process is complete, Jenkins gets the test results from Maven and displays these results on the project page.

Scheduling builds

One of the important features of Jenkins is that it automatically triggers the build, based on defined criteria. Jenkins provides multiple ways to trigger the build process under the Build Trigger configuration. Build Trigger can be set at a specific time. In the previous example, it was set to trigger the process every day at 10 p.m. This provides the ability to nightly run tests unattended, so that you can see the results the next morning.

Test results

Jenkins provides the ability to display test results by reading the results files generated by unit test frameworks. It also archives these results, which can be used to generate various metrics over time.

See also

  • The Configuring Jenkins for continuous integration recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.220