This project is a template for Salmon's test automation framework, which provides structured and standard way of creating automated test scripts for GUI and API level tests across salmon projects
This is a reusable automation framework that blends together Selenium WebDriver and Cucumber JVM (incorporating Gherkin and the BDD 'Given, When Then' testing construct)
The framework incorporates design principle of BDD (Behaviour driven development) which promotes writing acceptance tests by describing behaviour of application under test in simple english language from the perspective of its stakeholders. Having test written in Natural language helps the Project Team (Product Owners, Business Analysts, Development and QA team) to understand and track the requirements
Supports Custom Page Object model which represents the screens of AUT as a series of objects and encapsulates the fields represented by a page which ultimately avoids duplication and improves code maintainability and readability.
The test automation framework is comprised of following tools and libraries
*Cucumber-JVM:- BDD Framework
*Custom Page Object Pattern and utility functions
*Selenium WebDriver : - Browser automation framework
*JAVA: - Programming language
*TestNg: - TestNg Java testing framework
*Maven: - Build tool
*Jenkins: - Continuous Integration
*Lombok: - Java utility api
*PicoContainer: - Dependency Injection
*Git (optional): - Version Control
*Github (optional): - Git repository hosted server
*Intellij Or Eclipse: - Integrated Development Environment
*Hamcrest: - Matcher's
*Loggers: - Simple Logging Facade for Java
*Joda-Time: - Java Date time Api
*SonarQube (optional): - Code Quality and Code Coverage
*DbUtils Mysql (optional): - Java Database utility api
*Rest-Assured (optional): - Restful Api framework
Head of Testing
ngee@salmon.com
Test Automation Architect
gkarvir@salmon.com
Configure Ubuntu / Windows and setup: -
*Java 7
*Git
*Maven
Open Terminal or command line cd to the desired folder where the test automation source code needs to be checkout
Run command git clone https://github.com/salmontest/salmontest.git
This will download the latest template source code
Configure and Install Following Plugins
File >> Setting >> Plugins >> Browser Repositories>
*Cucumber for Java *Gherkin *lombok *Git Integration *GitHub *Maven Integration *SonarQube (optional)
File>Import Project> Browse to SalmonAutomationFramework
Configure and Install Following Plugins
Help>>Install new software
*Cucumber for Java
http://cucumber.github.com/cucumber-eclipse/update-site
*lombok Download lombok.jar from http://projectlombok.org/download.html Copy the Jar to eclipse installation directory right click the Jar>Open with Open JDK or Oracle JDK Java 7 Runtime Follow the Installation Steps
*TestNg
*Git Integration
*SonarQube (optional)
File>Import>Maven>Existing Maven Projects>Next> Browse to SalmonAutomationFramework Ensure pom.xml is found Finish
open terminal cd to test root directory run "mvn clean eclipse:eclipse"
Plugin configuration for Cucumber Feature Open Run Configurations Select Cucumber Feature and create one new configuration Project: salmonAutomationFramework Feature: src/salmonAutomationFramework/src/test/resources/features Glue: com.salmon.test.step_definitions Repors: monochrome, pretty
URL, Browser Configuration, Test Suites to Run Open "pom.xml" Scroll to Profile section : - Choose desired profile e.g "dev" for running locally
<!-- Development environment @ my local machine -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Application under test-->
<site.url>http://www.lloydspharmacy.com/</site.url>
<!-- Service under test-->
<api.url>http://www.dulux.com.sg</api.url>
<!-- AUT has default desired port-->
<site.port></site.port>
<!-- AUT has default base path-->
<site.basepath></site.basepath>
<!--platform to run e.g linux64, mac32, win32, win64-->
<platform>linux64</platform>
<!--Desired browser to run e.g firefox,chrome,iexplore -->
<browser>firefox</browser>
<!--To Run parallel Test suite specify the type of Run Files which can be run in parallel -->
<testToRun>**/*ATSuite.class</testToRun>
<!--Database Params -->
<jdbcUrl>jdbc:mysql://localhost:3306/sonar</jdbcUrl>
<jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
<jdbcUser>sonar</jdbcUser>
<jdbcPwd>sonar</jdbcPwd>
</properties>
Command Line
cd to root ot salmonAutomationFramework project directory
mvn clean install -DskipTests
mvn clean install
OR
mvn clean install -P dev
*Note -P dev is default profile hence doesn't need to be specified for every run
mvn clean install -Dcucumber.options="--tags @gui --tags ~@api" -P single
** Note "~" before tag means this specific tag will not run
A report will be generated at /target/cucumber-report/index.html
The report will be available as part of configured Jenkins test build
**Cucumber plugin for Jenkins needs to be installed
These files contains the acceptance criteria which are written in Gherkin Language and contains various scenarios.
The feature files are tagged with "@tagname" to group common feature files
File Extension: *.feature
Location: "/home/dev/src/salmonAutomationFramework/src/test/resources/features"
Directory: Separate directories for GUI and API tests, Group common features files in a
single directory
File Conventions:Meaning full name "WebRegister.feature"
Example:
@gui
Feature: REGISTER:- As a new customer of Lloydspharmacy I would like to register
Scenario:Perform a New registration for a customer
Given I navigate to the Lloydspharmacy "HOME" page
PageObjects are used to store the WebElements for a Web Page.
A good practice is to have a separate class for every single WebPage.
To avoid duplication for multiple pages which have common web page elements a Parent class can be created
and the child class can then inherit.
Every Page class extends "PageObject.class" to make use of the WebDriver Object and utility functions.
In case of Parent and Child Class, Parent class extends PageObject class and child class extends Parent class
Location: /home/dev/src/salmonAutomationFramework/src/test/java/com/salmon/test/pageobjects
Directory structure: Group common Page Objects classes in a single directory e.g Login Functionality Classes in Login Directory
File Conventions:Every Class file ends with Page.class (Homepage.class)
Example:
public class HomeSamplePage extends PageObject {
private By headerSignInLink = By.cssSelector("#headerSignInLink a");
public void clickSignInLink() {
waitForExpectedElement(headerSignInLink).click();
}
}
Every steps defined in Feature file needs to be implemented in Step Definitions Class
Location: /home/dev/src/salmonAutomationFramework/src/test/java/com/salmon/test/step_definitions
Directory structure: Separate directories for GUI and API tests, Group common step definition files in a
single directory
File Conventions:Every Class file ends with Steps.class (LoginSteps.class)
Example:
public class HomePageSteps {
private HomeSamplePage homePage = new HomeSamplePage();
@And("^i click on Sign In on the Home Page$")
public void i_click_on_Sign_In_on__the_Home_Page() throws Throwable {
homePage.clickSignInLink();
}
}
Test Suites are used to run a group of Tests which are tagged and represented in form of Feature files & Scenarios
Location: /home/dev/src/salmonAutomationFramework/src/test/java/com/salmon/test File Conventions:Every Class file ends with Suite.class (RunWebATSuite.class)
@CucumberOptions(features = "target/test-classes", tags = {"@gui"},
monochrome = true, plugin = {
"pretty", "html:target/cucumber-report/runwebat",
"json:target/cucumber-report/runwebat/cucumber.json"
})
public class RunWebATSuite extends AbstractTestNGCucumberTests {
}
Where: -
features: represent the location of feature files from the compiled build
tags: multiple tags can be specified by comma separated denotation, if a specific tag needs to be excluded then this
can be specified by "" . e.g "@api" feature files tagged with "~api" will not be run as a part of Test Suite.
format: html and json reports are created. if a TesSuite is renamed then change the reporting directory name for both reports
*command line using Maven:- mvn clean install -P dev *IDE Plugins: - Eclipse or Intellij via TestNg plugin or Maven plugin or Cucumber-Java plugin *IDE TestNg Suite xml: - file located at "src/test/resources" TestNGRunTestSuite.xml (Right click and run as TestNg)