Saturday, 3 October 2015

Test Automation Framework using Jenkins, GitHub, Maven, Selenium Grid, and TestNG

The Problem
  
You’re looking to automation web application using Selenium WebDriver for a full end-to-end / UI automation testing, there could be many challenges -

Challenge 1 - Selenium tests take a long time to run, how to speed up test execution, How to run script across the browser

Challenge 2 - Your team is distributed across geography, how team members develop, debug & update would test scripts at a central repository.

Challenge 3 - How to make sure code is not broken & there is no build failure after last night script update?

Challenge 4 - Who will own the responsibility to run script & share execution result (success/failure) with team & stakeholder?

Challenge 5 - How to manage project dependency & make sure across the team same version of jar file is used.


A Solution

Solution 1 - By leveraging Selenium Grid, we could speed up test execution & reduce test execution time. It provides ability to run parallel execution of test cases on multiple browser and operating system. Setup a Selenium Grid hub and nodes to run a battery of Selenium tests quickly.
           
Solution 2 - By leveraging Git/GitHub (private/public code repository) we can maintain web-based code repository and source code management, where every team member can upload their test scripts. It also provides access control and collaboration features such as wikis, task management, and bug tracking and feature requests for every project.

Solution 3 & 4 – By leveraging Jenkins, once configured on a central machine, it runs Selenium tests automatically several times a day (or as scheduled), or even each time there is a code commit (It allows to schedule build with GitHub with the git-plugin to run job on each commit, success/failure report is shared with stakeholder via email upon completion of build job)

Solution 5 - By leveraging Apache Maven in our test framework, this is a software project management and comprehension tool. Based on the concept of a project object model (POM),Maven manages a project's resource, build, reporting and documentation from a central piece of information.

General workflow

Maintain two branches on GitHub – Master & Stable. All new development & changes happens in branch Master. Stable branch contains successfully executable test scripts.

  1. Push changes to a branch Master or Initiate a Script run by clicking on [Build Now] on Jenkins Project page
  2. Jenkins detects a change pushed to Master
  3. Jenkins pulls in the latest changes & begins to run Selenium tests
  4. Upon completion of test execution, Jenkins sends execution report via email to configured email ID

Let’s dig in with an example


An Example

Jenkins CI to manage test execution & nodes from single interface -



 POM.xml which manages project dependency, goal & project lifecycle -


Test Java class which has tests for AUT

Test Execution Report

Conclusion
If you'd like to see the code of above mentioned project,  please write to us.

 Happy Testing!