This is a guest post written by Ravi Naidu.

What is Continuous Integration (CI)?

Continuous Integration is a practice that is supported by automated testing tools.  Implementing a successful CI practice within an organization requires discipline, particularly when your development environment contains a significant amount of complexity.

According to Martin Fowler of ThoughtWorks, continuous integration is a software development practice that requires team members to integrate their work frequently. Every person integrates at least daily, which leads to multiple integrations each day. Integrations are verified by an automated build that runs regression tests to detect integration errors as quickly as possible. Teams find that this approach leads to significantly fewer integration problems and enables development of cohesive software more rapidly.

Continuous integration involves integrating early and often. By integrating regularly, you can detect errors quickly, and locate them more easily. Each check-in is then verified by an automated build, allowing teams to detect problems early.

“Continuous Integration doesn’t get rid of bugs, but it does make them dramatically easier to find and remove”– Martin Fowler, Chief Scientist, ThoughtWorks

Adding Selenium Automated tests Continuous Integration

To achieve this we need to rely on the following. The below steps are for Java environment

Maintain a Selenium code repository:

All artifacts like Selenium automation framework, scripts, data files etc. required to build the project should be placed in the repository. The trunk should be the place for the working version of the scripts. Version control is achieved with SVN which can be installed as a plugin for eclipse.

Each Selenium automated developer commits their completed scripts to the trunk.

Automate the build:

The next step of CI is to automate the build. We can achieve this using Apache Ant or Maven. Ant is a complete Java build and deployment tool.

Why do we need a build tool?

Build tools are typically used to automate the process of

  1. Compiling code
  2. Package the binaries
  3. Deploy the binaries to the test server

To achieve this we use the Build.XML. Below is an example of Build.xml

<project basedir=“.” default=“runTest” name=“TestingDatadrivenPoc”>

 

<property name=“src” location=“./src” />

<property name=“bin” location=“./bin” />

<property name=“libs” location=“./lib” />

<property environment=“env” />

 

<path id=“classpath”>

<fileset dir=“${libs}” includes=“**/*.jar” />

<pathelement location=“${bin}” />

</path>

 

<target name=“clean”>

<echo message=“deleting existing bin directory” />

<delete dir=“${bin}” />

 

</target>

<target name=“init”>

<mkdir dir=“${bin}” />

</target>

 

<target name=“compile” depends=“clean,init”>

<echo message=“classpath:${test.classpath}” />

<echo message=“compiling……….” />

<javac destdir=“${bin}” srcdir=“${src}” classpathref=“classpath” includeantruntime=“false” debug=“true” debuglevel=“lines,source” />

</target>

 

<taskdef name=“testng” classname=“org.testng.TestNGAntTask”>

<classpath>

<pathelement location=“lib/testng-6.8.jar” />

</classpath>

</taskdef>

 

<target name=“runTest” depends=“compile”>

 

<mkdir dir=“testng_output” />

<!– Create the output directory. –>

<testng outputdir=“testng_output” classpathref=“classpath” haltonfailure=“true”>

 

<xmlfileset dir=“.” includes=“TestSuiteRunner.xml” />

</testng>

 

</target>

 

<propertyfile file=“buildnumber.properties” comment=“My properties”>

 

<entry key=“UniqueID” value=“${env.BUILD_NUMBER}” />

</propertyfile>

 

</project>

Continuous Build Integration:

The next step is continuous build integration and to achieve this we can use Jenkins or Hudson. Typically Jenkins can be used to run Selenium automated scripts on a Continuous Build Integration Machine. Jenkins is mapped to the trunk to pick the latest scripts available.

Build triggers can be set to either “Scheduled execution” or built after the development build is successfully built.

 

Once the development team build is a pass, we can have Sanity scripts or complete regression Selenium automated scripts executed. This could be achieved after every development build or nightly build. In case of nightly build we have the time to execute complete Selenium automated regression suite.

If you would like more information on Agile, DevOps or Software Testing, please visit my Software Testing Blog or my Software Testing YouTube Channel.