Thursday, December 8, 2016

DevOps (Continuous Integration) – Selenium & Cucumber using Maven in Jenkins

Selenium – Automated Testing Framework

Selenium is an open source automated testing software for web application released under Apache 2.0 license. Earliest version of Selenium tool was developed by Jason Huggins in 2004. Later, many people contributed in bringing the Selenium testing tool to its current level.

Selenium download is available at http://www.seleniumhq.org. It’s needs to be configured in IDE like eclipse & visual studio to be used.

Configuring Selenium in Jenkins –

Selenium testing job can be configured in Jenkins as freestyle or Maven project. In freestyle project Selenium job is executed through shell script running the testng.xml. Selenium testing as Maven project in Jenkins is done using pom.xml.

Freestyle Project ->

Create a Java project in Eclipse using option -> New -> Java Project -> Update Project Name -> Click Libraries -> Add External Jars -> Select Selenium-Server-Standalone Jar file -> Add Library – Select TestNG – Click Next – Click Finish – Click Finish ->


Create a script file (mac)/bat file (window) in the project directory using syntax – “java –cp bin;lib/* org.testng.TestNG testng.xml” and save the file in same directory locally.


Create a freestyle project in Jenkins using option –> New Item -> Update project name -> Select Freestyle project -> Press ok -> Click advance under General -> Select custom workspace ->update project home directory in the directory field ->


Next step , under build ->Press Add build step -> Select “Execute shell” -> Update script file name in the command field -> Press apply ->Press save ->


Now, a freestyle selenium project is ready to build in Jenkins.

Maven Project ->

Verify & insure your Eclipse have Maven and TestNG plugins installed -> Create a Maven project in Eclipse using option New -> Project -> Select Maven Project -> Click next -> Check “Create a simple project” -> Click Next -> Update group ID field –> update artifact ID field -> update name -> update description -> click finish ->


Update the pom.xml file with necessary Selenium & testng dependencies and testing.xml file location detail->


Create a test program & generate testng.xml using right click test java class -> Select TestNG -> Convert to TestNG -> save testng.xml file as per pom.xml location specification ->


Next, in Jenkins -> Create New item – Enter an item name -> Select Maven project -> Press ok -> Update pom.xml location file in build section -> Press apply –> Press save.


Now, maven selenium project ready to build in Jenkins.

Cucumber – Behaviour Driven Development

Cucumber is automated testing tool written in behaviour driven development style.

Configuring Cucumber in Jenkins –

Create a project in Eclipse using option -> New -> project -> select Maven project -> press next -> check ‘create a simple project’ -> Press next -> Update group ID -> Update artefact ID -> Update name -> Update description -> Press finish ->


Open pom.xml file -> Update latest stable selenium, junit, cucumber-java, cucumber-junit dependencies in the pom.xml -> Press control^S ->


Install cucumber software update for eclipse from chttp://cucumber.github.com/cucumber-eclipse/update-site using option help -> install new software -> Create a feature file ->


Create a package and java class in src/test/java folder using option new package -> Name the package -> New class -> Name the class -> Add reference of the feature file in the class ->


Create a test step package and java class in src/test/java folder using option new package -> Name package -> New class -> Name class -> Create test steps as per the feature file and reference as ‘glue’ in the earlier defined class - >


In Jenkins, create new project using option -> New Item -> Enter an item name -> Select Maven -> Click ok -> Update location of the the pom-xml file in next page under build section-> Press apply -> Press save ->

Now, Maven-Cucumber project is ready to build in Jenkins.


4 comments: