Upload
dasun-hettiarachchi
View
863
Download
114
Embed Size (px)
Citation preview
Cucumber Automation
Macys & Bloomingdales.com
What is Cucumber ?
• Behavior Driven Development and testing tool that executes plain text feature (Gherkin) descriptions with scenarios and determine whether the test passes or fails
BDD - Behavior Driven Development 1st - Describe what the software does -
Behavior 2nd - Write the code to fulfill it
• It separate software design from writing code • A merging of the concepts of Test Driven
Development and Domain Driven Design
TDD - Test Driven Development
• First the developer writes an test case according to the requirement and then implement the code to pass that test.
• This is more of a developer oriented approach, a more low level way of doing things
DDD - Domain Driven Design
• Encapsulate complex business logic in to a domain models. It closes the gap between business requirement and code
• Domain experts and product managers which directly involves with business decisions are preparing clear and concise specifications.
• Write specifications in natural language so everyone is on the same page - Each scenario describes how the system is being used
Building Blocks
Acceptance Criteria- Plain Text: Feature File with Scenarios
Step Definitions(Ruby)
DDD TDDBDD
How Cucumber works• Gherkin is the language that Cucumber
framework understands. • Cucumber Parser divides the input into
features, scenarios and steps. When you run the feature the trailing portion (after the keyword) of each step is matched to a Ruby code block called step definition
Gherkin ExampleFeature: Some terse yet descriptive text of what is desired In order to realize a named business value as an explicit system actor i want to gain some beneficial outcome which furthers the goal
Scenario: Some determinable business situationGiven some preconditionAnd some other preconditionWhen some action by the actorAnd some other actionAnd yet another actionThen some testable outcome is achievedAnd something else we can check happens too
Example from MacysFeature: SignIn Page
Scenario: Successful SignIn - Credit SignIn Page Given I successfully sign-in from the Credit SignIn Page Then I should land on the Manage My/Your Credit Account And I should verify that I am signed-in # Notes: # verify sign-in related cookies # Navigation - # BCOM - Credit Services from footer - Manage My Credi
Account # MCOM - MACYS' CREDIT CARD - Manage Your Credit
Account
How to use Cucumber?1. Describe behavior in plain text2. Write a step definition in Ruby3. Run and watch it fail4. Write code to make the step pass5. Run again and see the step pass6. Repeat 2-5 until green like a cuke7. Repeat 1-6 until the money runs out
Gherkin Feature File Creation
What is Gherkin ? Gherkin is a language that is understandable
by the humans. In other words Gherkin is used to elaborate
requirements of a system in the most simplest form.
Cucumber framework understands Gherkin syntaxes and executes them as automated test cases.
Gherkin Feature Files Structure
Feature: Title– Tags
Scenario: Title– Given [context]– When [event]– And [more event]– Then [outcome]– And [another outcome]
ExampleFeature: Mathematical Operations@wipScenario: Addition Given I have X And I have Y too When I add X to Y Then I should see Z
Gherkin Feature Files
Gherkin file is saved with *.feature extension and is typically known as a feature file.
Every feature file stands for one test case. The test case converted into Gherkin is
saved in *.feature extension
What is a feature file? • A Feature file describes a feature or
a part of a feature with representative examples of expected outcomes.
• Cucumber uses these files to validate some system functionality against its specifications.
• Feature files are plain-text files, ideally stored in the same version control system as the related project.
What is a scenario?
• A scenario describes a key example of the feature. It will describe how the system delivers value to the stakeholder.
• The goal of the scenario is to clearly describe the goal that the steps are trying to validate.
Gherkin Keywords
Precondition -> Given
Test Action -> When
Outcome -> Then
Gherkin KeywordsAnd – And keyword is used when either there
are multiple preconditions or multiple excepted results.
Comments in Gherkin Comments have to start with “#”
sign
– EG:• # Note:• # use valid credentials to log in to the
profile
Scenario OutlineFeature: Sign in MCOM
Scenario Outline: SignIn Page - Rendering Regular SignIn Page
Given I am on the Regular SignIn Page as a guest user Then I verify the attributes of the Regular SignIn Page When I navigate to the "<SIGNIN_LINK>" Then I verify that the "<SIGNIN_LINK>" page is rendered Examples: | SIGNIN_LINK | | forgot your password? | | looking for your gift registry? | | see all the benefits of creating a profile | | Privacy Policy |
TablesFeature: As a customer, I verify my account
page
Scenario: Verify Macys Credit Card PagesGiven I visit the web site as a guest userWhen I sign-in to my profileAnd I navigate to credit card pageThen I verify Credit card page links below
| Apply Today || Credit Account Summary || Pay Bill online |
#Notes
Variables Scenario: Verify guest checkout till order review page
Given I visit the web site as a guest userWhen I add a “less_than_$99” product to my bagAnd I verify the basic attributes of the Shopping bag pageThen I checkout until I reach the "shipping" page as a "guest" userAnd I verify the basic attributes of the Shipping PageThen I continue checking out until I reach the "payment" pageAnd I verify the basic attributes of the Payment PageThen I continue checking out until I reach the "order review" pageAnd I verify the order details in Order Review Page
Variables• The quotes will allow the automation
engineer to write step definitions that accept a variable.
• The advantage here is that it introduces reusable steps.
• As new scenarios get written, there would be fewer steps to automate.
Should?/ Should Not• In all the “Then” steps, the word should/
should not is always followed by “I’. • The word should/ should not is a keyword in
the underlying cucumber framework that the automation engineer uses for assertion.
• If that statement is false, then the step will return a failure message to cucumber
• Ex: - Then I “should” be on the “Home” Page - Then I “should not” be on the “Home”
Page
Gherkin StandardsEvery keyword should start with an upper
case letter – Example: Given , WhenEvery line must start with upper case.Use simplest possible action verbs –
Assuming the reader of the feature file is a non technical and is not a expert.
Gherkin StandardsSupport your test steps with comments, when
appropriateTest data fields should be left blank in the format
shown. Example: Names , Email Addresses , Password , Zip codes – <Email Address>
Provide as many pre-conditions as possible, in order to successfully automate the test case
What makes a good feature file?
• About the business domain – not the software design
• In domain language • It is a specification, not a script • Easy to understand • Focus is on a single thing • It is precise and testable • Self-Explanatory • Consistent • Easy to access
What makes a bad feature file
• Long sentences • Repetitious sentences • Repetitive scenarios • A never ending story • Commentary
Demo
AssignmentAutomate the following Scenario in
Macys.comFeature: Macys LoginScenarios: - Login with invalid account information- Login with valid account information
Thank you
Q & A