Introduction to Cucumber Automation
-
Upload
dasun-hettiarachchi -
Category
Documents
-
view
879 -
download
114
Transcript of Introduction to Cucumber Automation
![Page 1: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/1.jpg)
Cucumber Automation
Macys & Bloomingdales.com
![Page 2: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/2.jpg)
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
![Page 3: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/4.jpg)
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
![Page 5: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/5.jpg)
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
![Page 6: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/6.jpg)
Building Blocks
Acceptance Criteria- Plain Text: Feature File with Scenarios
Step Definitions(Ruby)
DDD TDDBDD
![Page 7: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/7.jpg)
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
![Page 8: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/8.jpg)
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
![Page 9: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/9.jpg)
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
![Page 10: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/11.jpg)
Gherkin Feature File Creation
![Page 12: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/12.jpg)
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.
![Page 13: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/13.jpg)
Gherkin Feature Files Structure
Feature: Title– Tags
Scenario: Title– Given [context]– When [event]– And [more event]– Then [outcome]– And [another outcome]
![Page 14: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/14.jpg)
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
![Page 15: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/16.jpg)
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.
![Page 17: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/17.jpg)
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.
![Page 18: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/18.jpg)
Gherkin Keywords
Precondition -> Given
Test Action -> When
Outcome -> Then
![Page 19: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/19.jpg)
Gherkin KeywordsAnd – And keyword is used when either there
are multiple preconditions or multiple excepted results.
![Page 20: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/20.jpg)
Comments in Gherkin Comments have to start with “#”
sign
– EG:• # Note:• # use valid credentials to log in to the
profile
![Page 21: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/21.jpg)
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 |
![Page 22: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/23.jpg)
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
![Page 24: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/24.jpg)
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.
![Page 25: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/26.jpg)
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.
![Page 27: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/27.jpg)
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
![Page 28: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/28.jpg)
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
![Page 29: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/29.jpg)
What makes a bad feature file
• Long sentences • Repetitious sentences • Repetitive scenarios • A never ending story • Commentary
![Page 30: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/30.jpg)
Demo
![Page 31: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/31.jpg)
AssignmentAutomate the following Scenario in
Macys.comFeature: Macys LoginScenarios: - Login with invalid account information- Login with valid account information
![Page 32: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/32.jpg)
Thank you
![Page 33: Introduction to Cucumber Automation](https://reader033.fdocuments.net/reader033/viewer/2022061311/587375711a28ab3c1a8b63ab/html5/thumbnails/33.jpg)
Q & A