Upload
kms-technology
View
483
Download
6
Embed Size (px)
Citation preview
Behavior-Driven Developmentand Automation Testing
using Cucumber Framework.
Trong Bui
KMS-Technology
http://www.kms-technology.com
06|12|2014
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
2BDD 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
Webinar Agenda:
• 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
Introduction
BDD AUTOMATION TESTING WITH CUCUMBER 5
Software Development Life Cycle
BDD AUTOMATION TESTING WITH CUCUMBER 6
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.
As a user,
I want to login into the system when I provide username and password.
Scenario: login successfully
Given the login page is opening
When I input username into the username textbox
And I input valid password into the password textbox
And I click Login button
Then I am on the Home page
BDD AUTOMATION TESTING WITH CUCUMBER 9
and normal Automation Test
@Test
public void fb_login_test() throws Exception {
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys("[email protected]");
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’s all about Given, When and Then – Maps easily to user stories
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 stories to 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
What is Cucumber
BDD AUTOMATION TESTING WITH CUCUMBER 17
Cucumber definition:
From Wikipedia, Cucumber is a software tool that computer programmers use for testing other software. It runs automated acceptance tests written in a Behavior-Driven Development (BDD) style.
BDD AUTOMATION TESTING WITH CUCUMBER 18
How cucumber works:
BDD AUTOMATION TESTING WITH CUCUMBER 19
BDD Automation Test with Cucumber
BDD AUTOMATION TESTING WITH CUCUMBER 20
Example of BDD scenario:
Feature: login to the system.
As a user,
I want to login into the system when I provide username and password.
Scenario: login successfully
Given the login page is opening
When I input username into the username textbox
And I input valid password into the password textbox
And I click Login button
Then I am on the Home page
BDD AUTOMATION TESTING WITH CUCUMBER 21
BDD Scenario with parameters:
BDD AUTOMATION TESTING WITH CUCUMBER 22
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_in field, :with => value
end
23
BDD scenario with multi dataset:
BDD AUTOMATION TESTING WITH CUCUMBER 24
Cucumber Live Demo
BDD AUTOMATION TESTING WITH CUCUMBER 25
Environment setup:
• Windows:
– Install Ruby Installer• Download: http://rubyinstaller.org/downloads [Ruby 1.9.3-p125]
• Install: rubyinstaller-xxx.exe
• Verify: gem
– Install Ruby DevKit• Download: http://rubyinstaller.org/downloads [DevKit-tdm-32-
xxx]
• Run: DevKit-tdm-32-xxx.exe
• Generate config.yml file: ruby dk.rb init
• Install DevKit: ruby dk.rb
• Test Installation: gem install rdiscount --platform=ruby
BDD AUTOMATION TESTING WITH CUCUMBER 26
Q&A
BDD AUTOMATION TESTING WITH CUCUMBER 27
APPENDIX
APPENDIX – PAGE OBJECT PATTERN 29
UI Test Setup with Page Object Pattern
APPENDIX – PAGE OBJECT PATTERN 30
PAGE OBJECT PATTERN
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 the maintainability of 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