34
Behavior-Driven Development and Automation Testing using Cucumber Framework. Trong Bui KMS-Technology [email protected] http://www.kms-technology.com 06|12|2014

Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Embed Size (px)

Citation preview

Page 1: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Behavior-Driven Developmentand Automation Testing

using Cucumber Framework.

Trong Bui

KMS-Technology

[email protected]

http://www.kms-technology.com

06|12|2014

Page 2: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 3: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 4: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 5: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Introduction

BDD AUTOMATION TESTING WITH CUCUMBER 5

Page 6: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Software Development Life Cycle

BDD AUTOMATION TESTING WITH CUCUMBER 6

Page 7: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Classic example on collaboration skills

BDD AUTOMATION TESTING WITH CUCUMBER 7

Page 8: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Skill gap and review dependency

BDD AUTOMATION TESTING WITH CUCUMBER 8

Page 9: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 10: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 11: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

What is Behavior Driven Development (BDD)

BDD AUTOMATION TESTING WITH CUCUMBER 11

Page 12: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 13: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 14: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 15: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 16: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 17: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

What is Cucumber

BDD AUTOMATION TESTING WITH CUCUMBER 17

Page 18: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 19: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

How cucumber works:

BDD AUTOMATION TESTING WITH CUCUMBER 19

Page 20: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

BDD Automation Test with Cucumber

BDD AUTOMATION TESTING WITH CUCUMBER 20

Page 21: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 22: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

BDD Scenario with parameters:

BDD AUTOMATION TESTING WITH CUCUMBER 22

Page 23: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 24: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

BDD scenario with multi dataset:

BDD AUTOMATION TESTING WITH CUCUMBER 24

Page 25: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Cucumber Live Demo

BDD AUTOMATION TESTING WITH CUCUMBER 25

Page 26: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 27: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Q&A

BDD AUTOMATION TESTING WITH CUCUMBER 27

Page 28: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

THANK YOU

© 2013 KMS Technology

Page 29: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

APPENDIX

APPENDIX – PAGE OBJECT PATTERN 29

Page 30: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

UI Test Setup with Page Object Pattern

APPENDIX – PAGE OBJECT PATTERN 30

Page 31: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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 32: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

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

Page 33: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

Cucumber Live Demo with Page Object Pattern

APPENDIX – PAGE OBJECT PATTERN 33

Page 34: Behavior-Driven Development and Automation Testing Using Cucumber Framework Webinar

References

• Spring + Behavior-Driven-Development

• Cukes.info

• The Cucumber Book

• Page Object Pattern

BDD AUTOMATION TESTING WITH CUCUMBER 34