About: KMS-Technology
•Global Company
–U.S. Company
–Development Center in Ho Chi Minh City, Vietnam
–Act local, think global (around-the-clock / distributed global team model)
–480 resources globally
•Proven and Experienced
–Founded in January, 2009
–100% of clients are reference-able
–Microsoft Gold Partner
•Value Driven Philosophy
–Focus all aspects of business on delivering quality and value to our clients
2
BDD AUTOMATION TESTING WITH CUCUMBER
About: Trong Bui
•QA Architect, Automation Test Lead at KMS-Technology
•8 years experience in Software testing, including 4 years experience in Automation Test.
•Test tools: Cucumber, Selenium.
BDD AUTOMATION TESTING WITH CUCUMBER 3
WebinarAgenda:
•Introduction
•What is Behavior Driven Development (BDD)
•What is Cucumber
•BDD Automation Test with Cucumber
•Cucumber Live Demo
•Appendix:
–UI Test Setup with Page Object Pattern
–Cucumber Demo with Page Object Pattern
BDD AUTOMATION TESTING WITH CUCUMBER 4
Classic example on collaboration skills
BDD AUTOMATION TESTING WITH CUCUMBER 7
Skill gap and review dependency
BDD AUTOMATION TESTING WITH CUCUMBER 8
Specific example of an requirement
Feature: login to the system.
Asa user,
I want to login into the system when I provide username and password.
Scenario:login successfully
Giventhe login page is opening
WhenI input username into the username textbox
AndI input valid password into the password textbox
AndI click Login button
ThenI am on the Home page
BDD AUTOMATION TESTING WITH CUCUMBER 9
and normal Automation Test
@Test
public void fb_login_test() throwsException {
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys("bddtest@yahoo.com");
driver.findElement(By.id("pass")).clear();
driver.findElement(By.id("pass")).sendKeys("********");
driver.findElement(By.id("u_0_e")).click();
}
BDD AUTOMATION TESTING WITH CUCUMBER 10
What is Behavior Driven Development (BDD)
BDD AUTOMATION TESTING WITH CUCUMBER 11
Definition:
Behavior-driven development (or BDD) is an agile software development technique that encourages collaboration between developers, QA and non-technical or business participants in a software project.
BDD AUTOMATION TESTING WITH CUCUMBER 12
More specific:
It’sallaboutGiven,WhenandThen–Mapseasilytouserstories
Extends Test Driven Development (TDD) by utilizing natural language that non-technical stakeholders can understand.
Encourages collaboration between Domain experts, Business Analysts, QA Engineers, Developers & Business Owners / Stakeholders
Driven by Business Value and finally, with the aim of delivering "software that matters".
BDD AUTOMATION TESTING WITH CUCUMBER 13
BDD scenario detail:
A description of each specific case of the narrative. Such a scenario has the following structure:
BDD AUTOMATION TESTING WITH CUCUMBER 14
Mapping User storiesto BDD scenarios:
User story
BDD scenario
As a calculator user, I want to add two numbers so that I can do addition.
Given I have two numbers 500 & 500 When I add them upThen I should get result 1000
As a Math teacher, I want to automate marks sorting process so that I can declare top 5 in my class.
Given a list of numbersWhen I sort the listThen the list will be in numerical order
As a QA engineer, I want to check a critical feature so that I can do smoke test easily.
Given I visit Google.comWhen I type ‘TestingWhiz' as a search string
Then I should get search results matching TestingWhiz
BDD AUTOMATION TESTING WITH CUCUMBER 15
Tooling principles:
The tooling reads a specification document.
The tooling directly understands completely formal parts of the ubiquitous language (such as the Given keyword in the example above).
Each individual clause in a scenario is transformed into some sort of parameter for a test for the user story.
The framework then executes the test for each scenario, with the parameters from that scenario.
BDD AUTOMATION TESTING WITH CUCUMBER 16
Cucumber definition:
From Wikipedia, Cucumberis asoftwaretool thatcomputer programmersuse for testing other software. It runs automatedacceptance testswritten in aBehavior-Driven Development(BDD) style.
BDD AUTOMATION TESTING WITH CUCUMBER 18
Example of BDD scenario:
Feature: login to the system.
Asa user,
I want to login into the system when I provide username and password.
Scenario:login successfully
Giventhe login page is opening
WhenI input username into the username textbox
AndI input valid password into the password textbox
AndI click Login button
ThenI am on the Home page
BDD AUTOMATION TESTING WITH CUCUMBER 21
How Cucumber works:
BDD AUTOMATION TESTING WITH CUCUMBER
Given/^I launch "([^"]*)" page$/ do |page|
visit(page)
End
When/^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_infield, :with => value
end
23
BDD scenario with multi dataset:
BDD AUTOMATION TESTING WITH CUCUMBER 24
UI Test Setup with Page Object Pattern
APPENDIX –PAGE OBJECT PATTERN 30
PAGEOBJECTPATTERN
Page Object Pattern is UI Automation Test good practice.
It represents the screens of Web app as a series of objects and encapsulates the features represented by a page.
It allows us to model the UI in our tests.
A page object is an object-oriented class that serves as an interface to a page of your AUT.
APPENDIX –PAGE OBJECT PATTERN 31
Page Object Pattern advantages:
Reduces the duplication of code
Makes tests more readable and robust
Improves themaintainabilityof tests, particularly when there is frequent change in the AUT.(Useful in Agile methodology based projects)
APPENDIX –PAGE OBJECT PATTERN 32
Cucumber Live Demo with Page Object Pattern
APPENDIX –PAGE OBJECT PATTERN 33
References
•Spring + Behavior-Driven-Development
•Cukes.info
•The Cucumber Book
•Page Object Pattern
BDD AUTOMATION TESTING WITH CUCUMBER 34