You are here: Ultra Guide>Automation Web>CucumberGherkinExamples (06 Oct 2021, MayaMcKela)Edit AttachTags

Cucumber Feature Files & Implementation Examples

  • The page contains several examples of feature files and their implementation
  • The project is setup using Maven, TestNG, Selenium, and Cucumber
  • For help setting up these dependencies, see the following Wiki pages:
  • For each example, there is a
    1. Feature tab showing the scenario written in Gherkin
    2. The glue code generated prior to implementation
    3. The final working version of the test implementation

Page Object Model Usage

  • The tests uses a simple Page Object Model (POM) to allow for concise and reusable code
  • A page object model typically contains a root page class (sometime called Page or BasePage)
  • The BasePage can contain functionality that is common to all pages
  • More specific pages such as Homepage, Account, Login, Search Results or Checkout would then extend the BasePage to add functions specific to that page
  • See Java Generics and POM in Selenium and POM with Selenium and Cucumber for more information

This is a simple product search example. Rather than implement the details of the When the User searches for "strawberry" step specific to this feature, we'll implement it a common page which is re-usable among different tests.

Building on the previous example, we'll instead use Scenario Outline and Examples to enhance the test to search for different products & the number of expected results

Account Login (Version 1)

Here we have two login scenarios which are slightly different.
  • They share a common Background step
  • The login steps are the same but use different accounts
  • The status message after attempting to login is different

Account Login (Version 2)

While the previous example meets our requirements, there's a few opportunities for enhancement:
  • The valid/invalid login scenarios are similar but require separate methods to submit information
  • The login information is hard coded into our implementation
  • We could again use Scenario Outline and Examples to create a more robust test
  • This would also allow easier testing of additional accounts

Customer Checkout (Data Tables)

This feature demonstrates the use of a data table with a key/value map to populate customer information.

API Tests (Multiple Data Tables)

This feature demonstrates the use several data tables to test an API, where every test has the same steps.

-- MayaMcKela - 06 Oct 2021
Topic revision: r6 - 06 Oct 2021, MayaMcKela
© 2020 Ultranauts - 75 Broad Street, 2nd Floor, Suite 206, New York, NY 10004 - info@ultranauts.co