SlideShare a Scribd company logo
- Vikas Sarin, PMP, CTFL, M.E.(SS)
 Why BDD?
 What is BDD
 Cucumber
 Cucumber is for BDD
 Selenium and its Tools
 Selenium Environmental Setup
 Selenium Architecture
 Selenium Script
 Cucumber Environmental Setup
 Cucumber Annotations
 Cucumber Feature File
 Cucumber Step Definition and Runner File
 Cucumber Output Results
 Cucumber Scenario Outline
 Cucumber Tags
 Cucumber Hooks
 Cucumber Reports
 Summary
CucumberSeleniumWD
CucumberSeleniumWD
 It is about delivering working functionality as
soon as possible.
 Feedback.
CucumberSeleniumWD
 Work is done from the perspective of the
user
 Can slice vertically but narrowly
 Tests behavior of the system
 Executable requirements
 Need to move as fast
as business
 Appropriate feedback loop
 Manual regression is
EXPENSIVE
 Unit Tests confirm that you built it right
(INSIDE OUT)
 Acceptance Tests confirm that you build the
right thing (OUTSIDE IN)
 BDD is a synthesis and refinement of practices
stemming from TDD and ATDD(Acceptance Test
Driven Development). BDD augments TDD and ATDD
with the following tactics:
◦ Apply the ‘Five Whys’ principle to each proposed User Story
so that its purpose is clearly related to business outcomes
◦ Thinking ‘from the Outside-In’, in other words implement
only those behaviours which contribute most directly to
these business outcomes, so to minimize waste
◦ Describe behaviours in a single notation which is directly
accessible to domain experts, testers and developers, so to
improve communication
◦ Apply these techniques all the way down to the lowest
levels of abstraction of the software, paying particular
attention to the distribution of behaviour, so that evolution
remains cheap
 2003:agiledox, the ancestor of BDD, is a tool
generating technical documentation automatically
from JUnit tests, written by Chris Stevenson
 2004: in order to test his hypotheses about de-
emphasizing "test" terminology in favor of "behavior",
Dan North releases JBehave
 2006: in collaboration with Chris Matts, North
proposes the given-when-then canvas to expand the
scope of BDD to business analysis and documents the
approach in “Introducing BDD”
 2006-2009: several new tools are released
confirming the community's investment in BDD, such
as RSpec or more recently, Cucumber and GivWenZen
 User authentication feature would be having
the key Test Scenarios which needs to be
passed in order to call it as a success:
◦ The user should be able to login with correct
username and correct password.
◦ The user should be able to login with incorrect
username and correct password.
◦ The user should be able to login with incorrect
username and correct password.
CucumberSeleniumWD
 A team using BDD should be able to provide a significant portion of "functional documentation"
in the form of User Stories augmented with executable scenarios or examples.
 Instead of referring to "tests", a BDD practitioner will prefer the terms "scenario" and
"specification". As currently practiced, BDD aims to gather in a single place the specification of
an outcome valuable to a user, generally using the role-feature matrix of (User Stories), as well
as examples or scenarios expressed in the form given-when-then; these two notations being
often considered the most readable.
 In emphasizing the term "specification", the intent of BDD is to provide a single answer to what
many Agile teams view as separate activities: the creation of unit tests and "technical" code on
one hand, the creation of functional tests and "features" on the other hand. This should lead to
increased collaboration between developers, test specialists, and domain experts.
 Rather than refer to "the unit tests of a class", a practitioner or a team using BDD prefers to
speak of "the specifications of the behavior of the class". This reflects a greater focus on the
documentary role of such specifications: their names are expected to be more expressive, and,
when completed with their description in given-when-then format, to serve as technical
documentation.
 Rather than refer to "functional tests", the preferred term will be "specifications of the
product's behavior". The technical aspects of BDD are placed on an equal footing with
techniques encouraging more effective conversation with customers, users and domain
experts.
 In addition to refactoring techniques already present in TDD, the design philosophy in BDD
pays particular attention to appropriate distribution of responsibilities among classes, which
leads its practitioners to emphasize “mocking”.
 Teams already using TDD or ATDD may want to consider BDD for
several reasons:
 BDD offers more precise guidance on organizing the
conversation between developers, testers and domain experts
 notations originating in the BDD approach, in particular the
given-when-then canvas, are closer to everyday language and
have a shallower learning curve compared to those of tools such
as Fit/FitNesse
 tools targeting a BDD approach generally afford the automatic
generation of technical and end user documentation from BDD
"specifications"
 Implementing changes more efficiently
 Quick feedback
 Higher product quality
 Less rework
 Better work alignment to priority
 All stakeholders involved in the discussion drives out clear
and concise specifications centred around business value.
 Write specifications in natural language so everyone is on the
same page
 Turn the specification into acceptance tests that guarantees
the software does as it is intended
 Use those tests as the software evolves to guarantee that it
continues to work as intended.
 Specifications are documentation – each scenario describes
how the system is being used
 Cucumber is one such open source tool, which supports behavior
driven development. To be more precise, Cucumber can be
defined as a testing framework, driven by plain English text. It
serves as documentation, automated tests, and a development
aid – all in one.
 So what does Cucumber do? It can be described in the following
steps −
 Cucumber reads the code written in plain English text (Language
Gherkin – to be introduced later in this tutorial) in the feature file
(to be introduced later).
 It finds the exact match of each step in the step definition (a
code file - details provided later in the tutorial).
 The piece of code to be executed can be different software
frameworks like Selenium, Ruby on Rails, etc. Not every BDD
framework tool supports every tool.
 This has become the reason for Cucumber's popularity over
other frameworks, like JBehave, JDave, Easyb, etc.
CucumberSeleniumWD
CucumberSeleniumWD
 Cucumber supports different languages like
Java.net and Ruby.
 It acts as a bridge between the business and
technical language. We can accomplish this by
creating a test case in plain English text.
 It allows the test script to be written without
knowledge of any code, it allows the involvement
of non-programmers as well.
 It serves the purpose of end-to-end test
framework unlike other tools.
 Due to simple test script architecture, Cucumber
provides code reusability.
 Selenium is an open-source and a portable automated
software testing tool for testing web applications.
 It has capabilities to operate across different browsers and
operating systems.
 Selenium is not just a single tool but a set of tools that helps
testers to automate web-based applications more efficiently.
Tool Description
Selenium IDE
Selenium Integrated Development Environment (IDE) is a Firefox
plugin that lets testers to record their actions as they follow the
workflow that they need to test.
Selenium RC
Selenium Remote Control (RC) was the flagship testing
framework that allowed more than simple browser actions and
linear execution. It makes use of the full power of programming
languages such as Java, C#, PHP, Python, Ruby and PERL to create
more complex tests.
Selenium WebDriver
Selenium WebDriver is the successor to Selenium RC which sends
commands directly to the browser and retrieves results.
Selenium Grid
Selenium Grid is a tool used to run parallel tests across different
machines and different browsers simultaneously which results in
minimized execution time.
Tools in Selenium Suite:
Selenium QTP
Selenium is an open-source tool.
QTP is a commercial tool and there is a
cost involved in each one of the licenses.
Can be extended for various technologies
that expose DOM.
Limited add-ons and needs add-ons for
each one of the technologies.
Has capabilities to execute scripts across
different browsers.
Can run tests in specific versions of
Firefox , IE, and Chrome.
Can execute scripts on various operating
systems.
Works only with Windows.
Supports mobile devices.
Supports mobile devices with the help of
third-party tools.
Executes tests within the browser, so
focus is NOT required while script
execution is in progress.
Needs Focus during script execution, as
the tool acts on the browser (mimics user
actions).
Can execute tests in parallel with the use
of Selenium Grids.
QTP cannot execute tests in parallel,
however integrating QTP with QC allows
testers to execute in parallel. QC is also a
commercial tool.
Selenium QTP
Supports only web based
applications.
Can test both web and desktop
applications.
No feature such as Object
Repository/Recovery Scenario
QTP has built-in object repositories
and recovery scenarios.
No IDE, so the script development
won't be as fast as QTP.
More intuitive IDE; automation can
be achieved faster.
Cannot access controls within the
browser.
Can access controls within the
browser such as favorites bar,
backward, and forward buttons.
No default test report generation.
Default test result generation
within the tool.
For parameterization, users has to
rely on the programming language.
Parameterization is built-in and
easy to implement.
 The Selenium Web Driver environmental setup
steps are as:
◦ Download and Install Java
◦ Download and Configure Eclipse
◦ Configure FireBug and FirePath
◦ Configure Selenium WebDriver
 WebDriver is a tool for automating testing web applications. It is popularly
known as Selenium 2.0. WebDriver uses a different underlying framework,
while Selenium RC uses JavaScript Selenium-Core embedded within the
browser which has got some limitations. WebDriver interacts directly with the
browser without any intermediary, unlike Selenium RC that depends on a
server. It is used in the following context:
◦ Multi-browser testing including improved functionality for browsers which is not
well-supported by Selenium RC (Selenium 1.0)
◦ Handling multiple frames, multiple browser windows, popups, and alerts
◦ Complex page navigation
◦ Advanced user navigation such as drag-and-drop
◦ AJAX-based UI elements
CucumberSeleniumWD
Selenium RC Selenium WebDriver
The architecture of Selenium RC is
complicated, as the server needs
to be up and running before
starting a test.
WebDriver's architecture is simpler
than Selenium RC, as it controls
the browser from the OS level.
Selenium server acts as a
middleman between the browser
and Selenese commands.
WebDriver interacts directly with
the browser and uses the
browser's engine to control it.
Selenium RC script execution is
slower, since it uses a Javascript
to interact with RC.
WebDriver is faster, as it interacts
directly with the browser.
Selenium RC cannot support
headless execution as it needs a
real browser to work with.
WebDriver can support the
headless execution.
It's a simple and small API.
Complex and a bit large API as
compared to RC.
Less object-oriented API. Purely object oriented API.
Cannot test mobile Applications.
Can test iPhone/Android
applications.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class webdriverdemo {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
//Puts an Implicit wait, Will wait for 10 seconds before
throwing exception
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
//Launch website
driver.navigate().to("http://www.calculator.net/");
//Maximize the browser
driver.manage().window().maximize();
// Click on Math Calculators
driver.findElement(By.xpath(".//*[@id='menu']/div[3]/a")).c
lick();
// Click on Percent Calculators
driver.findElement(By.xpath(".//*[@id='menu']/div[4]/div[3]/a")).
click();
// Enter value 10 in the first number of the percent
Calculator
driver.findElement(By.id("cpar1")).sendKeys("10");
// Enter value 50 in the second number of the percent
Calculator
driver.findElement(By.id("cpar2")).sendKeys("50");
// Click Calculate Button
driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[
2]/td/input[2]")).click();
// Get the Result Text based on its xpath
String result =
driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")).
getText();
// Print a Log In message to the screen
System.out.println(" The Result is " + result);
//Close the Browser.
driver.close();
}
}
CucumberSeleniumWD
 Environment Setup for Cucumber, Selenium
WebDriver and Java & Eclipse on Windows
Machine:
◦ Prerequisities:
 Why we need – Java is a robust programming language.
Cucumber supports Java platform for the execution.
 How to install –
 Download Java SDK and install -
http://www.oracle.com/technetwork/java/javase/downloa
ds/index.html
 Eclipse
◦ Why we need – Eclipse is an Integrated
Development Environment (IDE). It contains a base
workspace and an extensible plug-in system for
customizing the environment.
◦ How to Install –
 Make sure Java is installed on the machine
 Download Eclipse from https://eclipse.org/downloads/
 Unzip in a folder and Eclipse is installed
 Maven –
◦ Why we need –
 Maven is a build automation tool used primarily for
Java projects.
◦ How to install –
 Download Maven from
https://maven.apache.org/download.cgi
 Unzip the file and create the MAVEN_HOME and Edit
Path Environment Variables as:
 Maven –
◦ Download MAVEN plugin from Eclipse
◦ Open Eclipse
◦ Go to Help -> Eclipse Marketplace -> Search Maven
-> Maven Integration for Eclipse -> INSTALL
 Cucumber –
◦ Create a Maven Project
 Open File -> New -> Others -> Maven -> Maven
Project -> Next
 Provide ‘group Id’ and ‘artifact Id’
 Cucumber –
◦ Open pom.xml
 Go to package explorer on the left hand side of Eclipse
 Expand the project CucumberTest
 Select pom.xml to open as a Text
 Cucumber –
◦ Add pom.xml is in the edit mode, create dependencies tag,
<dependencies></dependencies>, inside the project tag
◦ Inside the dependencies tag, create dependency tags:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependencies>
 Cucumber –
◦ Open pom.xml
 Go to package explorer on the left hand side of Eclipse
 Expand the project CucumberTest
 Select pom.xml to open as a Text
 Cucumber –
◦ Verify binaries:
 Once pom.xml is edited successfully, save it
 Go to Project -> Clean – It will take a few minutes
 Maven repository as shown in the following
screenshot:
 Gherkin –
◦ The language, in which this executable feature files is written, is
known as Gherkin. Gherkin is a plain English text language, which
helps the tool - Cucumber to interpret and execute the test
scripts.
 Why Gherkin? – Because of BDD only.
◦ BDD incorporates different prospectives while creating test
scripts, like, development prospective, business prospective, etc.
◦ There is a risk of not using the common language for test script
conceptualizing because people from different communities on
the program/project, like developers, project mangers, product
owners, business analysts, testers, etc. do not belong to the same
category.
◦ Gherkin provides the common set of keywords in English text &
other 39 native languages, French, Finnish, Indonesian,
Hungarian, Hindi, Urdu, Gujarati, etc., which can be used by
people amongst the different community and yet get the same
output in thee form of test scripts
 Gherkin example –
◦ Feature: Login functionality for a social networking site.
Given I am a social networking site user. When I enter
username1. And I enter password as password1. Then I
should be redirected to the home page of the site.
◦ Example of few other keywords –
 Background
 But
 *
 Scenario Outline
 Examples
 Gherkin parses each step written in Step Definition
File as per the corresponding matching Feature File
steps
CucumberSeleniumWD
 A feature usually contains a list of scenarios to be
tested for that feature stored in a file with the
extension as ‘.feature’. A file in which we store
features, description about the features and scenarios
to be tested is known as Feature File.
 A simple feature file consists of the following
keywords/parts –
◦ Feature – Name of the feature under test
◦ Description – Describe about feature under test
◦ Scenario – What is the Test Scenario
◦ Given – Prerequisite before the test steps execute
◦ When – Specific condition which should match in order to
execute the next step
◦ Then – What should happen if the condition mentioned in
WHEN is satisfied
 Use # to comment out a statement in a feature file
 Annotation is a predefine text which holds a specified meaning.
It lets the compiler know what should be done upon execution.
Annotations are used in the feature files Cucumber has got the
following few annotations –
◦ Given – describes the pre-requisite for the test to be executed
◦ When – defines the trigger point for any test scenario execution
◦ Then – holds the expected result for the test to be executed
◦ And – provides the logical AND condition between any two statements.
AND can be used in conjunction with GIVEN, WHEN and THEN statement
◦ But – signifies logical OR condition between any two statements. OR can
be used in conjunction with GIVEN, WHEN and THEN
◦ Scenario – details about the scenario under the test needs to be captured
after the keyword “Scenario:”
◦ Background – Background generally has the instruction on what to setup
before each scenario runs. However, it gets executed after “Before” hook.
◦ Scenario Outline – replaces variables/keywords with the value from the
table. Each row in the table is considered to be a scenario.
◦ Examples – example of the data records in rows for the input to the Step
Definition functions arguments
 www.facebook.com is a social networking site
and has to be tested. The following features
would be tested –
◦ Create and remove the user from the social
networking site
◦ User login functionality for the social networking
site
◦ Sharing photos or videos on the social networking
site
◦ Sending a friend request
◦ Logout
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
Feature: annotation
#This is how background can be used to eliminate duplicate steps
Background:
User navigates to Facebook Given
I am on Facebook login page
#Scenario with AND
Scenario: enter username and password and fail
When I enter username as "TOM"
And I enter password as "JERRY"
Then Login should fail
#Scenario with BUT
Scenario: enter username and pasword and fail with alternative for relogin
When I enter username as "TOM"
And I enter password as "JERRY"
Then Login should fail
But Relogin option should be available
annotation.java –
package Annotation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class annotation {
WebDriver driver = null;
@Given("^I am on Facebook login page$")
public void goToFacebook() {
driver = new FirefoxDriver();
driver.navigate().to("https://www.facebook.com/");
}
@When("^I enter username as "(.*)"$")
public void enterUsername(String arg1) {
driver.findElement(By.id("email")).sendKeys(arg1);
}
@When ("^I enter password as "(.*)"$")
public void enterPassword(String arg1) {
driver.findElement(By.id("pass")).sendKeys(arg1);
driver.findElement(By.id("u_0_v")).click();
}
@Then("^Login should fail$")
public void checkFail() {
if(driver.getCurrentUrl().equalsIgnoreCase(
“https://www.facebook.com/login.php?login_attempt=
1&lwv=110")){
System.out.println("Test1 Pass");
} else {
System.out.println("Test1 Failed");
}
driver.close();
}
@Then("^Relogin option should be available$")
public void checkRelogin() {
if(driver.getCurrentUrl().equalsIgnoreCase(
"https://www.facebook.com/login.php?login_attempt=
1&lwv=110")){
System.out.println("Test2 Pass");
} else {
System.out.println("Test2 Failed"); }
driver.close();
}
}
runTest.java –
package Annotation;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber"})
public class runTest { }
 Run the test using the following steps:
◦ Select runTest.java file from the package explorer
◦ Right-click and select the option ‘Run as’
◦ Select JUnit test
 The following would be observed on running this class for the
first scenario:
◦ Facebook opens in a new Firefox web-browser instance.
◦ TOM will be passed as an input to the username field.
◦ JERRY will be passed as an input to the password field.
◦ Login will be clicked.
◦ Message will be displayed on the browser regarding unsuccessful login.
◦ In the console, you will see “Test Pass” printed
scenoutline.feature –
Feature: Scenario Outline
Scenario Outline: Login functionality for a social networking site.
Given user navigates to Facebook
When I enter Username as "<username>" and Password as "<password>"
Then login should be unsuccessful
Examples:
| username | password |
| username1 | password1 |
| username2 | password2 |
annotation.java –
package Annotation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class annotation {
WebDriver driver = null;
@Given("^I am on Facebook login page$")
public void goToFacebook() {
driver = new FirefoxDriver();
driver.navigate().to("https://www.facebook.com/");
}
@When("^I enter Username as "([^"]*)"
and Password as "([^"]*)"$")
public void
I_enter_Username_as_and_Password_as(Stri
ng arg1, String arg2) {
driver.findElement(By.id("email")).sendKeys(a
rg1);
driver.findElement(By.id("pass")).sendKeys(ar
g2);
driver.findElement(By.id("u_0_v")).click();
}
@Then("^login should be unsuccessful$")
public void validateRelogin() {
if(driver.getCurrentUrl().equalsIgnoreCase(
"https://www.facebook.com/login.php?login_attempt=
1&lwv=110")){
System.out.println("Test Pass");
} else {
System.out.println("Test Failed");
}
driver.close();
}
}
 The following would be observed on running the runTest.java-
 Facebook opens in a new Firefox web-browser instance.
 Username1 and password1 will be passed as an input to username
and password field.
 Login will be clicked.
 Message will be displayed on the browser regarding unsuccessful
login.
 In the console, you will see “Test Pass” printed.
 Other scenario would be executed for username2 and password2
 To manage the execution of selective scenarios for
a purpose(Smoke Test/Regression Test, ), different
prospectives(Developer/QA/BA), different
status(Ready for execution/Work in progress)
Cucumber provides Tags in the feature file.
 The scenarios could have Tags at the top of them in
the feature file. Later, in the runner file, specific tag
can be specified to execute
 Tag starts with “@” and can have any text without
space to define the tag. e.g., @SmokeTest
 There is no limit in defining the Tags within feature file
 The Tags can be derived based on use and scenarios to be executed
 There are mainly 2 types of Tags –
◦ Default Tag – Default Tag has their predefined meanings. e.g., @Dev, @Ignore
◦ Custom Tag – Custom Tag provides full flexibility to choose appropriate test for
defining tag
 More than one Tag can be defined for a Scenario in a Feature File
 Multiple Tags can be defined with or/and logical operations:
◦ Or in runner class - @dev,@wip
◦ And in runner classs - [@dev,@wip]
 “~” can be used in the Runner file options to exclude the Scenarios defined in
Feature File. e.g.,
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber"}, tags = {"~@SmokeTest"})
public class runTest { }
 cucumberTag.feature –
Feature: Cucumber Tag
Scenario Outline: Login functionality for a social networking site.
Given user navigates to Facebook
When I enter Username as "<username>" and Password as
"<password>"
Then login should be unsuccessful
Examples:
| username | password |
| username1 | password1 |
| username2 | password2 |
@SmokeTest
Scenario: navigate to facebook
Given user navigates to Facebook
When I enter Username as "<>" and Password as "<>"
Then the user should be redirected to login retry
annotation.java –
package Annotation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class annotation {
WebDriver driver = null;
@Given("^I am on Facebook login page$")
public void goToFacebook() {
driver = new FirefoxDriver();
driver.navigate().to("https://www.facebook.com/");
}
@When("^I enter Username as "([^"]*)" and
Password as "([^"]*)"$")
public void
I_enter_Username_as_and_Password_as(String arg1,
String arg2) {
driver.findElement(By.id("email")).sendKeys(arg1);
driver.findElement(By.id("pass")).sendKeys(arg2);
driver.findElement(By.id("u_0_v")).click();
}
@Then("^login should be unsuccessful$")
public void validateRelogin() {
if(driver.getCurrentUrl().equalsIgnoreCase(
"https://www.facebook.com/login.php?login_attempt=1&lwv=110
")){
System.out.println("Test Pass");
} else {
System.out.println("Test Failed");
}
driver.close();
}
@Then("^User should be redirected to login retry$")
public void loginRetry() {
if(driver.getCurrentUrl().equalsIgnoreCase(
"https://www.facebook.com/login.php?login_attempt=
1&lwv=110")){
System.out.println("Test Pass");
} else {
System.out.println("Test Failed");
}
driver.close(); }
}
 runTest.java –
package cucumberTag;
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber"})
public class runTest { }
 The following would be the result of the execution
of this Runner File-
◦ Facebook opens in a new Firefox web-browser instance
◦ No value will be provided to the username and the password
field
◦ Login will be clicked
◦ Login retry page will be loaded
 Cucumber hook allows to manage the workflow of
the code and reduce the code redundancy
 e.g., To setup and cleanup for the Multiple Test
Scenarios for a feature would use @Before and
@After tags respectively. @Before hook executes
before the Test Scenario for setup and @After hook
executes after the Test Scenario for cleanup.
 Hooks can be executed with specific tag. e.g.,
@Before(@Web)
 Or/and logical concept for tags can also be applied.
e.g., @Before(@dev,@wip), @Before(@dev,~@wip)
hookTest.java –
package hookTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class hookTest{
WebDriver driver = null;
@Before public void setUp(){
driver = new FirefoxDriver();
}
@Given("^I am on Facebook login page$")
public void goToFacebook() {
driver.navigate().to("https://www.facebook.com/");
}
@When("^I enter Username as "([^"]*)" and
Password as "([^"]*)"$")
public void
I_enter_Username_as_and_Password_as(String arg1,
String arg2) {
driver.findElement(By.id("email")).sendKeys(arg1);
driver.findElement(By.id("pass")).sendKeys(arg2);
driver.findElement(By.id("u_0_v")).click();
}
@Then("^login should be unsuccessful$")
public void validateRelogin() {
if(driver.getCurrentUrl().equalsIgnoreCase(
"https://www.facebook.com/login.php?login_attempt=1&lwv=1
10")){
System.out.println("Test Pass");
} else {
System.out.println("Test Failed");
}
driver.close();
}
@After
public void cleanUp(){
driver.close();
}
}
HTML Report: runTest.java
package CucumberReport;
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options( format = {"pretty",
"html:target/Destination"} )
//Specifying pretty as a format option ensure
that HTML report will be generated.
//When we specify html:target/Destination - It
will generate the HTML report inside the
Destination folder, in the target folder of the
maven project.
public class runTest { }
JSON Report: runTest.java
package CucumberReport;
import org.junit.runner.RunWith; import
cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(
format={"json:target/Destination/cucumber
.json"})
//When we specify
json:target/Destination/cucumber.json - It
will generate the JSON report inside the
Destination folder, in the target folder of the
maven project.
public class runTest {}
CucumberSeleniumWD
HTML:
JSON:
 Why BDD?
 What is BDD
 Cucumber
 Cucumber is for BDD
 Selenium and its Tools
 Selenium Environmental Setup
 Selenium Architecture
 Selenium Script
 Cucumber Environmental Setup
 Cucumber Annotations
 Cucumber Feature File
 Cucumber Step Definition and Runner File
 Cucumber Output Results
 Cucumber Scenario Outline
 Cucumber Tags
 Cucumber Hooks
 Cucumber Reports
CucumberSeleniumWD
Ad

More Related Content

What's hot (20)

Team Foundation Server Process Templates For Effective Project Management
Team Foundation Server Process Templates For Effective Project ManagementTeam Foundation Server Process Templates For Effective Project Management
Team Foundation Server Process Templates For Effective Project Management
Aaron Bjork
 
TDD and BDD and ATDD
TDD and BDD and ATDDTDD and BDD and ATDD
TDD and BDD and ATDD
Anuar Nurmakanov
 
How to run an Enterprise PHP Shop
How to run an Enterprise PHP ShopHow to run an Enterprise PHP Shop
How to run an Enterprise PHP Shop
Jim Plush
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Test driven development and react js application go hand in hand
Test driven development and react js application go hand in handTest driven development and react js application go hand in hand
Test driven development and react js application go hand in hand
Katy Slemon
 
Spec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlowSpec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlow
Sarah Dutkiewicz
 
Ashok_Resume
Ashok_ResumeAshok_Resume
Ashok_Resume
Ashok Gangavarapu
 
Introduction to CodeFactory
Introduction to CodeFactoryIntroduction to CodeFactory
Introduction to CodeFactory
LifeCycle Delivery
 
Refactoring legacy code driven by tests - ITA
Refactoring legacy code driven by tests -  ITARefactoring legacy code driven by tests -  ITA
Refactoring legacy code driven by tests - ITA
Luca Minudel
 
An Introduction to Dependency Injection
An Introduction to Dependency InjectionAn Introduction to Dependency Injection
An Introduction to Dependency Injection
Adam Stephensen
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
Adam Englander
 
Kishore_Kandavalli_Resume
Kishore_Kandavalli_ResumeKishore_Kandavalli_Resume
Kishore_Kandavalli_Resume
kishore kandavalli
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
Volodymyr Voytyshyn
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven Development
Steven Mak
 
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
RIF-Technology
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Gherkin /BDD intro
Ryan Thomas Hewitt★CSM★CSPO★ITIL
 
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Katy Slemon
 
Agile & DevOps - It's all about project success
Agile & DevOps - It's all about project successAgile & DevOps - It's all about project success
Agile & DevOps - It's all about project success
Adam Stephensen
 
Critical Capabilities to Shifting Left the Right Way
Critical Capabilities to Shifting Left the Right WayCritical Capabilities to Shifting Left the Right Way
Critical Capabilities to Shifting Left the Right Way
SmartBear
 
Coding Naked
Coding NakedCoding Naked
Coding Naked
Caleb Jenkins
 
Team Foundation Server Process Templates For Effective Project Management
Team Foundation Server Process Templates For Effective Project ManagementTeam Foundation Server Process Templates For Effective Project Management
Team Foundation Server Process Templates For Effective Project Management
Aaron Bjork
 
How to run an Enterprise PHP Shop
How to run an Enterprise PHP ShopHow to run an Enterprise PHP Shop
How to run an Enterprise PHP Shop
Jim Plush
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Test driven development and react js application go hand in hand
Test driven development and react js application go hand in handTest driven development and react js application go hand in hand
Test driven development and react js application go hand in hand
Katy Slemon
 
Spec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlowSpec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlow
Sarah Dutkiewicz
 
Refactoring legacy code driven by tests - ITA
Refactoring legacy code driven by tests -  ITARefactoring legacy code driven by tests -  ITA
Refactoring legacy code driven by tests - ITA
Luca Minudel
 
An Introduction to Dependency Injection
An Introduction to Dependency InjectionAn Introduction to Dependency Injection
An Introduction to Dependency Injection
Adam Stephensen
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
Adam Englander
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
Volodymyr Voytyshyn
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven Development
Steven Mak
 
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
Антон Семенченко | (EPAM Systems, DPI.Solutions )Сравнительный анализ инстру...
RIF-Technology
 
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Tdd vs bdd vs atdd — developers’ methodologies to navigate complex developmen...
Katy Slemon
 
Agile & DevOps - It's all about project success
Agile & DevOps - It's all about project successAgile & DevOps - It's all about project success
Agile & DevOps - It's all about project success
Adam Stephensen
 
Critical Capabilities to Shifting Left the Right Way
Critical Capabilities to Shifting Left the Right WayCritical Capabilities to Shifting Left the Right Way
Critical Capabilities to Shifting Left the Right Way
SmartBear
 

Viewers also liked (10)

Ejercicio pimient r y v
Ejercicio pimient r y vEjercicio pimient r y v
Ejercicio pimient r y v
Alisson Geanella Macías
 
Laundry in dubai
Laundry in dubaiLaundry in dubai
Laundry in dubai
Eastern Rose Laundry
 
DanixaConde_Escala 2:2_FormatoA3
DanixaConde_Escala 2:2_FormatoA3DanixaConde_Escala 2:2_FormatoA3
DanixaConde_Escala 2:2_FormatoA3
danixaconde
 
'Brass Bands - An Undervalued Social Community Art'.
'Brass Bands - An Undervalued Social Community Art'. 'Brass Bands - An Undervalued Social Community Art'.
'Brass Bands - An Undervalued Social Community Art'.
Andy Goodwin
 
Liven Up Your Training
Liven Up Your TrainingLiven Up Your Training
Liven Up Your Training
Christine Bell
 
International sherry week campaign summary 2015
International sherry week campaign summary 2015International sherry week campaign summary 2015
International sherry week campaign summary 2015
Chelsea Anthon
 
Osb preliminary-results-2015
Osb preliminary-results-2015Osb preliminary-results-2015
Osb preliminary-results-2015
Bankir_Ru
 
Seek ppt
Seek pptSeek ppt
Seek ppt
seekhrsolutions
 
التصحيح الآلي
 التصحيح الآلي التصحيح الآلي
التصحيح الآلي
hifakhaldi
 
DanixaConde_Escala 2:2_FormatoA3
DanixaConde_Escala 2:2_FormatoA3DanixaConde_Escala 2:2_FormatoA3
DanixaConde_Escala 2:2_FormatoA3
danixaconde
 
'Brass Bands - An Undervalued Social Community Art'.
'Brass Bands - An Undervalued Social Community Art'. 'Brass Bands - An Undervalued Social Community Art'.
'Brass Bands - An Undervalued Social Community Art'.
Andy Goodwin
 
Liven Up Your Training
Liven Up Your TrainingLiven Up Your Training
Liven Up Your Training
Christine Bell
 
International sherry week campaign summary 2015
International sherry week campaign summary 2015International sherry week campaign summary 2015
International sherry week campaign summary 2015
Chelsea Anthon
 
Osb preliminary-results-2015
Osb preliminary-results-2015Osb preliminary-results-2015
Osb preliminary-results-2015
Bankir_Ru
 
التصحيح الآلي
 التصحيح الآلي التصحيح الآلي
التصحيح الآلي
hifakhaldi
 
Ad

Similar to CucumberSeleniumWD (20)

Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
QA or the Highway
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
rupeshchanchal
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
Nalin Goonawardana
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD
123abcda
 
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Colin Wren
 
TDD vs BDD_ Which Development Approach is Best for Your Project.pdf
TDD vs BDD_ Which Development Approach is Best for Your Project.pdfTDD vs BDD_ Which Development Approach is Best for Your Project.pdf
TDD vs BDD_ Which Development Approach is Best for Your Project.pdf
Steve Wortham
 
Choosing right-automation-tool
Choosing right-automation-toolChoosing right-automation-tool
Choosing right-automation-tool
BabuDevanandam
 
CV_AmalMandal
CV_AmalMandalCV_AmalMandal
CV_AmalMandal
Amal Mandal - Looking for a Change
 
Automated Test Framework with Cucumber
Automated Test Framework with CucumberAutomated Test Framework with Cucumber
Automated Test Framework with Cucumber
Ramesh Krishnan Ganesan
 
Ravindra Prasad
Ravindra PrasadRavindra Prasad
Ravindra Prasad
Ravindra Prasad
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Abdelkrim Boujraf
 
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Agile Testing Alliance
 
Microsoft DevOps Solution - DevOps
Microsoft DevOps Solution - DevOps  Microsoft DevOps Solution - DevOps
Microsoft DevOps Solution - DevOps
Chetan Gordhan
 
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
AgileNetwork
 
TDD vs. BDD: A Practical Comparison for Modern Development Teams
TDD vs. BDD: A Practical Comparison for Modern Development TeamsTDD vs. BDD: A Practical Comparison for Modern Development Teams
TDD vs. BDD: A Practical Comparison for Modern Development Teams
Shubham Joshi
 
PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
Adam Englander
 
Visual Studio ALM and DevOps Tools Walkthrough
Visual Studio ALM and DevOps Tools WalkthroughVisual Studio ALM and DevOps Tools Walkthrough
Visual Studio ALM and DevOps Tools Walkthrough
Angela Dugan
 
Agile Engineering
Agile EngineeringAgile Engineering
Agile Engineering
John Lewis
 
Ch17
Ch17Ch17
Ch17
phanleson
 
SCALABLE CI CD DEVOPS
SCALABLE CI CD DEVOPSSCALABLE CI CD DEVOPS
SCALABLE CI CD DEVOPS
G R VISHAL
 
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
QA or the Highway
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
rupeshchanchal
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
Nalin Goonawardana
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD
123abcda
 
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Colin Wren
 
TDD vs BDD_ Which Development Approach is Best for Your Project.pdf
TDD vs BDD_ Which Development Approach is Best for Your Project.pdfTDD vs BDD_ Which Development Approach is Best for Your Project.pdf
TDD vs BDD_ Which Development Approach is Best for Your Project.pdf
Steve Wortham
 
Choosing right-automation-tool
Choosing right-automation-toolChoosing right-automation-tool
Choosing right-automation-tool
BabuDevanandam
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Abdelkrim Boujraf
 
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Agile Testing Alliance
 
Microsoft DevOps Solution - DevOps
Microsoft DevOps Solution - DevOps  Microsoft DevOps Solution - DevOps
Microsoft DevOps Solution - DevOps
Chetan Gordhan
 
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
Agile Chennai 2021 | Achieving High DevOps Maturity through Platform Engineer...
AgileNetwork
 
TDD vs. BDD: A Practical Comparison for Modern Development Teams
TDD vs. BDD: A Practical Comparison for Modern Development TeamsTDD vs. BDD: A Practical Comparison for Modern Development Teams
TDD vs. BDD: A Practical Comparison for Modern Development Teams
Shubham Joshi
 
PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
Adam Englander
 
Visual Studio ALM and DevOps Tools Walkthrough
Visual Studio ALM and DevOps Tools WalkthroughVisual Studio ALM and DevOps Tools Walkthrough
Visual Studio ALM and DevOps Tools Walkthrough
Angela Dugan
 
Agile Engineering
Agile EngineeringAgile Engineering
Agile Engineering
John Lewis
 
SCALABLE CI CD DEVOPS
SCALABLE CI CD DEVOPSSCALABLE CI CD DEVOPS
SCALABLE CI CD DEVOPS
G R VISHAL
 
Ad

CucumberSeleniumWD

  • 1. - Vikas Sarin, PMP, CTFL, M.E.(SS)
  • 2.  Why BDD?  What is BDD  Cucumber  Cucumber is for BDD  Selenium and its Tools  Selenium Environmental Setup  Selenium Architecture  Selenium Script  Cucumber Environmental Setup  Cucumber Annotations  Cucumber Feature File  Cucumber Step Definition and Runner File  Cucumber Output Results  Cucumber Scenario Outline  Cucumber Tags  Cucumber Hooks  Cucumber Reports  Summary
  • 5.  It is about delivering working functionality as soon as possible.  Feedback.
  • 7.  Work is done from the perspective of the user  Can slice vertically but narrowly  Tests behavior of the system  Executable requirements  Need to move as fast as business  Appropriate feedback loop  Manual regression is EXPENSIVE
  • 8.  Unit Tests confirm that you built it right (INSIDE OUT)  Acceptance Tests confirm that you build the right thing (OUTSIDE IN)
  • 9.  BDD is a synthesis and refinement of practices stemming from TDD and ATDD(Acceptance Test Driven Development). BDD augments TDD and ATDD with the following tactics: ◦ Apply the ‘Five Whys’ principle to each proposed User Story so that its purpose is clearly related to business outcomes ◦ Thinking ‘from the Outside-In’, in other words implement only those behaviours which contribute most directly to these business outcomes, so to minimize waste ◦ Describe behaviours in a single notation which is directly accessible to domain experts, testers and developers, so to improve communication ◦ Apply these techniques all the way down to the lowest levels of abstraction of the software, paying particular attention to the distribution of behaviour, so that evolution remains cheap
  • 10.  2003:agiledox, the ancestor of BDD, is a tool generating technical documentation automatically from JUnit tests, written by Chris Stevenson  2004: in order to test his hypotheses about de- emphasizing "test" terminology in favor of "behavior", Dan North releases JBehave  2006: in collaboration with Chris Matts, North proposes the given-when-then canvas to expand the scope of BDD to business analysis and documents the approach in “Introducing BDD”  2006-2009: several new tools are released confirming the community's investment in BDD, such as RSpec or more recently, Cucumber and GivWenZen
  • 11.  User authentication feature would be having the key Test Scenarios which needs to be passed in order to call it as a success: ◦ The user should be able to login with correct username and correct password. ◦ The user should be able to login with incorrect username and correct password. ◦ The user should be able to login with incorrect username and correct password.
  • 13.  A team using BDD should be able to provide a significant portion of "functional documentation" in the form of User Stories augmented with executable scenarios or examples.  Instead of referring to "tests", a BDD practitioner will prefer the terms "scenario" and "specification". As currently practiced, BDD aims to gather in a single place the specification of an outcome valuable to a user, generally using the role-feature matrix of (User Stories), as well as examples or scenarios expressed in the form given-when-then; these two notations being often considered the most readable.  In emphasizing the term "specification", the intent of BDD is to provide a single answer to what many Agile teams view as separate activities: the creation of unit tests and "technical" code on one hand, the creation of functional tests and "features" on the other hand. This should lead to increased collaboration between developers, test specialists, and domain experts.  Rather than refer to "the unit tests of a class", a practitioner or a team using BDD prefers to speak of "the specifications of the behavior of the class". This reflects a greater focus on the documentary role of such specifications: their names are expected to be more expressive, and, when completed with their description in given-when-then format, to serve as technical documentation.  Rather than refer to "functional tests", the preferred term will be "specifications of the product's behavior". The technical aspects of BDD are placed on an equal footing with techniques encouraging more effective conversation with customers, users and domain experts.  In addition to refactoring techniques already present in TDD, the design philosophy in BDD pays particular attention to appropriate distribution of responsibilities among classes, which leads its practitioners to emphasize “mocking”.
  • 14.  Teams already using TDD or ATDD may want to consider BDD for several reasons:  BDD offers more precise guidance on organizing the conversation between developers, testers and domain experts  notations originating in the BDD approach, in particular the given-when-then canvas, are closer to everyday language and have a shallower learning curve compared to those of tools such as Fit/FitNesse  tools targeting a BDD approach generally afford the automatic generation of technical and end user documentation from BDD "specifications"  Implementing changes more efficiently  Quick feedback  Higher product quality  Less rework  Better work alignment to priority
  • 15.  All stakeholders involved in the discussion drives out clear and concise specifications centred around business value.  Write specifications in natural language so everyone is on the same page  Turn the specification into acceptance tests that guarantees the software does as it is intended  Use those tests as the software evolves to guarantee that it continues to work as intended.  Specifications are documentation – each scenario describes how the system is being used
  • 16.  Cucumber is one such open source tool, which supports behavior driven development. To be more precise, Cucumber can be defined as a testing framework, driven by plain English text. It serves as documentation, automated tests, and a development aid – all in one.  So what does Cucumber do? It can be described in the following steps −  Cucumber reads the code written in plain English text (Language Gherkin – to be introduced later in this tutorial) in the feature file (to be introduced later).  It finds the exact match of each step in the step definition (a code file - details provided later in the tutorial).  The piece of code to be executed can be different software frameworks like Selenium, Ruby on Rails, etc. Not every BDD framework tool supports every tool.  This has become the reason for Cucumber's popularity over other frameworks, like JBehave, JDave, Easyb, etc.
  • 19.  Cucumber supports different languages like Java.net and Ruby.  It acts as a bridge between the business and technical language. We can accomplish this by creating a test case in plain English text.  It allows the test script to be written without knowledge of any code, it allows the involvement of non-programmers as well.  It serves the purpose of end-to-end test framework unlike other tools.  Due to simple test script architecture, Cucumber provides code reusability.
  • 20.  Selenium is an open-source and a portable automated software testing tool for testing web applications.  It has capabilities to operate across different browsers and operating systems.  Selenium is not just a single tool but a set of tools that helps testers to automate web-based applications more efficiently.
  • 21. Tool Description Selenium IDE Selenium Integrated Development Environment (IDE) is a Firefox plugin that lets testers to record their actions as they follow the workflow that they need to test. Selenium RC Selenium Remote Control (RC) was the flagship testing framework that allowed more than simple browser actions and linear execution. It makes use of the full power of programming languages such as Java, C#, PHP, Python, Ruby and PERL to create more complex tests. Selenium WebDriver Selenium WebDriver is the successor to Selenium RC which sends commands directly to the browser and retrieves results. Selenium Grid Selenium Grid is a tool used to run parallel tests across different machines and different browsers simultaneously which results in minimized execution time. Tools in Selenium Suite:
  • 22. Selenium QTP Selenium is an open-source tool. QTP is a commercial tool and there is a cost involved in each one of the licenses. Can be extended for various technologies that expose DOM. Limited add-ons and needs add-ons for each one of the technologies. Has capabilities to execute scripts across different browsers. Can run tests in specific versions of Firefox , IE, and Chrome. Can execute scripts on various operating systems. Works only with Windows. Supports mobile devices. Supports mobile devices with the help of third-party tools. Executes tests within the browser, so focus is NOT required while script execution is in progress. Needs Focus during script execution, as the tool acts on the browser (mimics user actions). Can execute tests in parallel with the use of Selenium Grids. QTP cannot execute tests in parallel, however integrating QTP with QC allows testers to execute in parallel. QC is also a commercial tool.
  • 23. Selenium QTP Supports only web based applications. Can test both web and desktop applications. No feature such as Object Repository/Recovery Scenario QTP has built-in object repositories and recovery scenarios. No IDE, so the script development won't be as fast as QTP. More intuitive IDE; automation can be achieved faster. Cannot access controls within the browser. Can access controls within the browser such as favorites bar, backward, and forward buttons. No default test report generation. Default test result generation within the tool. For parameterization, users has to rely on the programming language. Parameterization is built-in and easy to implement.
  • 24.  The Selenium Web Driver environmental setup steps are as: ◦ Download and Install Java ◦ Download and Configure Eclipse ◦ Configure FireBug and FirePath ◦ Configure Selenium WebDriver
  • 25.  WebDriver is a tool for automating testing web applications. It is popularly known as Selenium 2.0. WebDriver uses a different underlying framework, while Selenium RC uses JavaScript Selenium-Core embedded within the browser which has got some limitations. WebDriver interacts directly with the browser without any intermediary, unlike Selenium RC that depends on a server. It is used in the following context: ◦ Multi-browser testing including improved functionality for browsers which is not well-supported by Selenium RC (Selenium 1.0) ◦ Handling multiple frames, multiple browser windows, popups, and alerts ◦ Complex page navigation ◦ Advanced user navigation such as drag-and-drop ◦ AJAX-based UI elements
  • 27. Selenium RC Selenium WebDriver The architecture of Selenium RC is complicated, as the server needs to be up and running before starting a test. WebDriver's architecture is simpler than Selenium RC, as it controls the browser from the OS level. Selenium server acts as a middleman between the browser and Selenese commands. WebDriver interacts directly with the browser and uses the browser's engine to control it. Selenium RC script execution is slower, since it uses a Javascript to interact with RC. WebDriver is faster, as it interacts directly with the browser. Selenium RC cannot support headless execution as it needs a real browser to work with. WebDriver can support the headless execution. It's a simple and small API. Complex and a bit large API as compared to RC. Less object-oriented API. Purely object oriented API. Cannot test mobile Applications. Can test iPhone/Android applications.
  • 28. import java.util.concurrent.TimeUnit; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; public class webdriverdemo { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); //Puts an Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website driver.navigate().to("http://www.calculator.net/"); //Maximize the browser driver.manage().window().maximize(); // Click on Math Calculators driver.findElement(By.xpath(".//*[@id='menu']/div[3]/a")).c lick(); // Click on Percent Calculators driver.findElement(By.xpath(".//*[@id='menu']/div[4]/div[3]/a")). click(); // Enter value 10 in the first number of the percent Calculator driver.findElement(By.id("cpar1")).sendKeys("10"); // Enter value 50 in the second number of the percent Calculator driver.findElement(By.id("cpar2")).sendKeys("50"); // Click Calculate Button driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[ 2]/td/input[2]")).click(); // Get the Result Text based on its xpath String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")). getText(); // Print a Log In message to the screen System.out.println(" The Result is " + result); //Close the Browser. driver.close(); } }
  • 30.  Environment Setup for Cucumber, Selenium WebDriver and Java & Eclipse on Windows Machine: ◦ Prerequisities:  Why we need – Java is a robust programming language. Cucumber supports Java platform for the execution.  How to install –  Download Java SDK and install - http://www.oracle.com/technetwork/java/javase/downloa ds/index.html
  • 31.  Eclipse ◦ Why we need – Eclipse is an Integrated Development Environment (IDE). It contains a base workspace and an extensible plug-in system for customizing the environment. ◦ How to Install –  Make sure Java is installed on the machine  Download Eclipse from https://eclipse.org/downloads/  Unzip in a folder and Eclipse is installed
  • 32.  Maven – ◦ Why we need –  Maven is a build automation tool used primarily for Java projects. ◦ How to install –  Download Maven from https://maven.apache.org/download.cgi  Unzip the file and create the MAVEN_HOME and Edit Path Environment Variables as:
  • 33.  Maven – ◦ Download MAVEN plugin from Eclipse ◦ Open Eclipse ◦ Go to Help -> Eclipse Marketplace -> Search Maven -> Maven Integration for Eclipse -> INSTALL
  • 34.  Cucumber – ◦ Create a Maven Project  Open File -> New -> Others -> Maven -> Maven Project -> Next  Provide ‘group Id’ and ‘artifact Id’
  • 35.  Cucumber – ◦ Open pom.xml  Go to package explorer on the left hand side of Eclipse  Expand the project CucumberTest  Select pom.xml to open as a Text
  • 36.  Cucumber – ◦ Add pom.xml is in the edit mode, create dependencies tag, <dependencies></dependencies>, inside the project tag ◦ Inside the dependencies tag, create dependency tags: <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependencies>
  • 37.  Cucumber – ◦ Open pom.xml  Go to package explorer on the left hand side of Eclipse  Expand the project CucumberTest  Select pom.xml to open as a Text
  • 38.  Cucumber – ◦ Verify binaries:  Once pom.xml is edited successfully, save it  Go to Project -> Clean – It will take a few minutes  Maven repository as shown in the following screenshot:
  • 39.  Gherkin – ◦ The language, in which this executable feature files is written, is known as Gherkin. Gherkin is a plain English text language, which helps the tool - Cucumber to interpret and execute the test scripts.  Why Gherkin? – Because of BDD only. ◦ BDD incorporates different prospectives while creating test scripts, like, development prospective, business prospective, etc. ◦ There is a risk of not using the common language for test script conceptualizing because people from different communities on the program/project, like developers, project mangers, product owners, business analysts, testers, etc. do not belong to the same category. ◦ Gherkin provides the common set of keywords in English text & other 39 native languages, French, Finnish, Indonesian, Hungarian, Hindi, Urdu, Gujarati, etc., which can be used by people amongst the different community and yet get the same output in thee form of test scripts
  • 40.  Gherkin example – ◦ Feature: Login functionality for a social networking site. Given I am a social networking site user. When I enter username1. And I enter password as password1. Then I should be redirected to the home page of the site. ◦ Example of few other keywords –  Background  But  *  Scenario Outline  Examples  Gherkin parses each step written in Step Definition File as per the corresponding matching Feature File steps
  • 42.  A feature usually contains a list of scenarios to be tested for that feature stored in a file with the extension as ‘.feature’. A file in which we store features, description about the features and scenarios to be tested is known as Feature File.  A simple feature file consists of the following keywords/parts – ◦ Feature – Name of the feature under test ◦ Description – Describe about feature under test ◦ Scenario – What is the Test Scenario ◦ Given – Prerequisite before the test steps execute ◦ When – Specific condition which should match in order to execute the next step ◦ Then – What should happen if the condition mentioned in WHEN is satisfied  Use # to comment out a statement in a feature file
  • 43.  Annotation is a predefine text which holds a specified meaning. It lets the compiler know what should be done upon execution. Annotations are used in the feature files Cucumber has got the following few annotations – ◦ Given – describes the pre-requisite for the test to be executed ◦ When – defines the trigger point for any test scenario execution ◦ Then – holds the expected result for the test to be executed ◦ And – provides the logical AND condition between any two statements. AND can be used in conjunction with GIVEN, WHEN and THEN statement ◦ But – signifies logical OR condition between any two statements. OR can be used in conjunction with GIVEN, WHEN and THEN ◦ Scenario – details about the scenario under the test needs to be captured after the keyword “Scenario:” ◦ Background – Background generally has the instruction on what to setup before each scenario runs. However, it gets executed after “Before” hook. ◦ Scenario Outline – replaces variables/keywords with the value from the table. Each row in the table is considered to be a scenario. ◦ Examples – example of the data records in rows for the input to the Step Definition functions arguments
  • 44.  www.facebook.com is a social networking site and has to be tested. The following features would be tested – ◦ Create and remove the user from the social networking site ◦ User login functionality for the social networking site ◦ Sharing photos or videos on the social networking site ◦ Sending a friend request ◦ Logout
  • 46. Feature: annotation #This is how background can be used to eliminate duplicate steps Background: User navigates to Facebook Given I am on Facebook login page #Scenario with AND Scenario: enter username and password and fail When I enter username as "TOM" And I enter password as "JERRY" Then Login should fail #Scenario with BUT Scenario: enter username and pasword and fail with alternative for relogin When I enter username as "TOM" And I enter password as "JERRY" Then Login should fail But Relogin option should be available
  • 47. annotation.java – package Annotation; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; public class annotation { WebDriver driver = null; @Given("^I am on Facebook login page$") public void goToFacebook() { driver = new FirefoxDriver(); driver.navigate().to("https://www.facebook.com/"); } @When("^I enter username as "(.*)"$") public void enterUsername(String arg1) { driver.findElement(By.id("email")).sendKeys(arg1); } @When ("^I enter password as "(.*)"$") public void enterPassword(String arg1) { driver.findElement(By.id("pass")).sendKeys(arg1); driver.findElement(By.id("u_0_v")).click(); } @Then("^Login should fail$") public void checkFail() { if(driver.getCurrentUrl().equalsIgnoreCase( “https://www.facebook.com/login.php?login_attempt= 1&lwv=110")){ System.out.println("Test1 Pass"); } else { System.out.println("Test1 Failed"); } driver.close(); } @Then("^Relogin option should be available$") public void checkRelogin() { if(driver.getCurrentUrl().equalsIgnoreCase( "https://www.facebook.com/login.php?login_attempt= 1&lwv=110")){ System.out.println("Test2 Pass"); } else { System.out.println("Test2 Failed"); } driver.close(); } }
  • 48. runTest.java – package Annotation; import org.junit.runner.RunWith; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @Cucumber.Options(format = {"pretty", "html:target/cucumber"}) public class runTest { }
  • 49.  Run the test using the following steps: ◦ Select runTest.java file from the package explorer ◦ Right-click and select the option ‘Run as’ ◦ Select JUnit test  The following would be observed on running this class for the first scenario: ◦ Facebook opens in a new Firefox web-browser instance. ◦ TOM will be passed as an input to the username field. ◦ JERRY will be passed as an input to the password field. ◦ Login will be clicked. ◦ Message will be displayed on the browser regarding unsuccessful login. ◦ In the console, you will see “Test Pass” printed
  • 50. scenoutline.feature – Feature: Scenario Outline Scenario Outline: Login functionality for a social networking site. Given user navigates to Facebook When I enter Username as "<username>" and Password as "<password>" Then login should be unsuccessful Examples: | username | password | | username1 | password1 | | username2 | password2 |
  • 51. annotation.java – package Annotation; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; public class annotation { WebDriver driver = null; @Given("^I am on Facebook login page$") public void goToFacebook() { driver = new FirefoxDriver(); driver.navigate().to("https://www.facebook.com/"); } @When("^I enter Username as "([^"]*)" and Password as "([^"]*)"$") public void I_enter_Username_as_and_Password_as(Stri ng arg1, String arg2) { driver.findElement(By.id("email")).sendKeys(a rg1); driver.findElement(By.id("pass")).sendKeys(ar g2); driver.findElement(By.id("u_0_v")).click(); } @Then("^login should be unsuccessful$") public void validateRelogin() { if(driver.getCurrentUrl().equalsIgnoreCase( "https://www.facebook.com/login.php?login_attempt= 1&lwv=110")){ System.out.println("Test Pass"); } else { System.out.println("Test Failed"); } driver.close(); } }
  • 52.  The following would be observed on running the runTest.java-  Facebook opens in a new Firefox web-browser instance.  Username1 and password1 will be passed as an input to username and password field.  Login will be clicked.  Message will be displayed on the browser regarding unsuccessful login.  In the console, you will see “Test Pass” printed.  Other scenario would be executed for username2 and password2
  • 53.  To manage the execution of selective scenarios for a purpose(Smoke Test/Regression Test, ), different prospectives(Developer/QA/BA), different status(Ready for execution/Work in progress) Cucumber provides Tags in the feature file.  The scenarios could have Tags at the top of them in the feature file. Later, in the runner file, specific tag can be specified to execute  Tag starts with “@” and can have any text without space to define the tag. e.g., @SmokeTest
  • 54.  There is no limit in defining the Tags within feature file  The Tags can be derived based on use and scenarios to be executed  There are mainly 2 types of Tags – ◦ Default Tag – Default Tag has their predefined meanings. e.g., @Dev, @Ignore ◦ Custom Tag – Custom Tag provides full flexibility to choose appropriate test for defining tag  More than one Tag can be defined for a Scenario in a Feature File  Multiple Tags can be defined with or/and logical operations: ◦ Or in runner class - @dev,@wip ◦ And in runner classs - [@dev,@wip]  “~” can be used in the Runner file options to exclude the Scenarios defined in Feature File. e.g., @RunWith(Cucumber.class) @Cucumber.Options(format = {"pretty", "html:target/cucumber"}, tags = {"~@SmokeTest"}) public class runTest { }
  • 55.  cucumberTag.feature – Feature: Cucumber Tag Scenario Outline: Login functionality for a social networking site. Given user navigates to Facebook When I enter Username as "<username>" and Password as "<password>" Then login should be unsuccessful Examples: | username | password | | username1 | password1 | | username2 | password2 | @SmokeTest Scenario: navigate to facebook Given user navigates to Facebook When I enter Username as "<>" and Password as "<>" Then the user should be redirected to login retry
  • 56. annotation.java – package Annotation; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; public class annotation { WebDriver driver = null; @Given("^I am on Facebook login page$") public void goToFacebook() { driver = new FirefoxDriver(); driver.navigate().to("https://www.facebook.com/"); } @When("^I enter Username as "([^"]*)" and Password as "([^"]*)"$") public void I_enter_Username_as_and_Password_as(String arg1, String arg2) { driver.findElement(By.id("email")).sendKeys(arg1); driver.findElement(By.id("pass")).sendKeys(arg2); driver.findElement(By.id("u_0_v")).click(); } @Then("^login should be unsuccessful$") public void validateRelogin() { if(driver.getCurrentUrl().equalsIgnoreCase( "https://www.facebook.com/login.php?login_attempt=1&lwv=110 ")){ System.out.println("Test Pass"); } else { System.out.println("Test Failed"); } driver.close(); } @Then("^User should be redirected to login retry$") public void loginRetry() { if(driver.getCurrentUrl().equalsIgnoreCase( "https://www.facebook.com/login.php?login_attempt= 1&lwv=110")){ System.out.println("Test Pass"); } else { System.out.println("Test Failed"); } driver.close(); } }
  • 57.  runTest.java – package cucumberTag; import org.junit.runner.RunWith; import cucumber.junit.Cucumber; @RunWith(Cucumber.class) @Cucumber.Options(format = {"pretty", "html:target/cucumber"}) public class runTest { }
  • 58.  The following would be the result of the execution of this Runner File- ◦ Facebook opens in a new Firefox web-browser instance ◦ No value will be provided to the username and the password field ◦ Login will be clicked ◦ Login retry page will be loaded
  • 59.  Cucumber hook allows to manage the workflow of the code and reduce the code redundancy  e.g., To setup and cleanup for the Multiple Test Scenarios for a feature would use @Before and @After tags respectively. @Before hook executes before the Test Scenario for setup and @After hook executes after the Test Scenario for cleanup.  Hooks can be executed with specific tag. e.g., @Before(@Web)  Or/and logical concept for tags can also be applied. e.g., @Before(@dev,@wip), @Before(@dev,~@wip)
  • 60. hookTest.java – package hookTest; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; public class hookTest{ WebDriver driver = null; @Before public void setUp(){ driver = new FirefoxDriver(); } @Given("^I am on Facebook login page$") public void goToFacebook() { driver.navigate().to("https://www.facebook.com/"); } @When("^I enter Username as "([^"]*)" and Password as "([^"]*)"$") public void I_enter_Username_as_and_Password_as(String arg1, String arg2) { driver.findElement(By.id("email")).sendKeys(arg1); driver.findElement(By.id("pass")).sendKeys(arg2); driver.findElement(By.id("u_0_v")).click(); } @Then("^login should be unsuccessful$") public void validateRelogin() { if(driver.getCurrentUrl().equalsIgnoreCase( "https://www.facebook.com/login.php?login_attempt=1&lwv=1 10")){ System.out.println("Test Pass"); } else { System.out.println("Test Failed"); } driver.close(); } @After public void cleanUp(){ driver.close(); } }
  • 61. HTML Report: runTest.java package CucumberReport; import org.junit.runner.RunWith; import cucumber.junit.Cucumber; @RunWith(Cucumber.class) @Cucumber.Options( format = {"pretty", "html:target/Destination"} ) //Specifying pretty as a format option ensure that HTML report will be generated. //When we specify html:target/Destination - It will generate the HTML report inside the Destination folder, in the target folder of the maven project. public class runTest { } JSON Report: runTest.java package CucumberReport; import org.junit.runner.RunWith; import cucumber.junit.Cucumber; @RunWith(Cucumber.class) @Cucumber.Options( format={"json:target/Destination/cucumber .json"}) //When we specify json:target/Destination/cucumber.json - It will generate the JSON report inside the Destination folder, in the target folder of the maven project. public class runTest {}
  • 64.  Why BDD?  What is BDD  Cucumber  Cucumber is for BDD  Selenium and its Tools  Selenium Environmental Setup  Selenium Architecture  Selenium Script  Cucumber Environmental Setup  Cucumber Annotations  Cucumber Feature File  Cucumber Step Definition and Runner File  Cucumber Output Results  Cucumber Scenario Outline  Cucumber Tags  Cucumber Hooks  Cucumber Reports