Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cucumber Cookbook

You're reading from   Cucumber Cookbook Over 35 hands-on recipes to efficiently master the art of behaviour-driven development using Cucumber-JVM

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781785286001
Length 162 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Shankar Garg Shankar Garg
Author Profile Icon Shankar Garg
Shankar Garg
Arrow right icon
View More author details
Toc

Table of Contents (8) Chapters Close

Preface 1. Writing Feature Files FREE CHAPTER 2. Creating Step Definitions 3. Enabling Fixtures 4. Configuring Cucumber 5. Running Cucumber 6. Building Cucumber Frameworks Index

Combining Scenarios, Backgrounds, and Scenario Outlines

Until now we have learned about Scenarios, Steps, Background, and Scenario Outline individually. But when a BA or a PO has to write the Feature file, they have to combine all these keywords to come up with a very efficient and expressive Feature file.

Consider writing a Feature file for a login functionality where the latter meets the following criteria:

  • The user should get an option to log in from the application's home page
  • To log in, a user should have a username and password
  • After a successful login, the user should be redirected to the home page
  • In case of an unsuccessful login, the user should get the appropriate message
  • The user should also get an option to register new users on the home page
  • The user should also be able to verify which users exist in the application (this Feature is not present on the GitHub landing page but has been added for to clarify concepts)

    Note

    All these requirements are specific to the behavior of the application, and none of them are concerned with how you implement these requirements.

How to do it…

Now we are going to use all the keywords we have explored until now, and we are going to create a login.feature file that specifies all the aforementioned requirements:

Feature: login Page
  In order to test login page
  As a Registered user
  I want to specify the login conditions

  Scenario: login flow
    Given user is on Application landing page
    And Sign in button is present on screen
    When user clicks on Sign in button
    Then user is displayed login screen
    When user enters "ShankarGarg" in username field
    And user enters "123456" in password field
    And user clicks Sign in button
    Then user is on home page
    And title of home page is "GitHub"

  Scenario Outline: Login fail - possible combinations
    Given user is on Application landing page
    When user clicks on Sign in button
    Then user is displayed login screen
    When user enters "<UserName>" in username field
    And user enters "<Password>" in password field
    And user clicks Sign in button
    Then user gets login failed error message

    Examples: 
      | UserName      | Password      |
      | wrongusername | 123456        |
      | ShankarGarg   | wrongpassword |
      | wrongusername | wrongpassword |

  Scenario: Existing user Verification
    Given user is on Application landing page
    Then we verify following user exists
      | Name    | Email           | Phone |
      | Shankar | [email protected] | 999   |
      | Ram     | [email protected]   | 888   |
      | Sham    | [email protected]  | 666   |

  Scenario: New User Registration
    Given user is on Application landing page
    When user enters "ShankarGarg" in username field
    And user enters "[email protected]" in password field
    And user enters "123456" in password field
    And user clicks on Signup for GitHub button
    Then user is successfully registered

How it works…

Here we have combined all the keywords and concepts discussed until now in this chapter. Let's go through each requirement one by one and analyze how and with which keyword we specified these requirements:

  • User should get an option to log in from the application home page—Scenario
  • For login, a user should have a username and password—Scenario
  • After successful login, the user should be redirected to the home page—Scenario
  • In case of unsuccessful login, the user should get the appropriate message—Scenario Outline
  • The user should also get an option to register new users on the home page—Scenario
  • The user should also be able to verify which users exist in the application—Data Table
You have been reading a chapter from
Cucumber Cookbook
Published in: Jun 2015
Publisher:
ISBN-13: 9781785286001
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image