Web testing with Cucumber for eCommerce applications

Since starting spriteCloud we have been setting up test automation suites for our clients using the frameworks Cucumber and Selenium webdriver. We notice that more and more eCommerce companies also show interest in test automation and particularly this test setup. Also, since the holiday season is typically the biggest revenue generating period, follow our 5 tips to make sure you fully test your site before the season starts.

When we look at the functionality of eCommerce sites in general, we see that every eCommerce application has roughly the same functionality. This typically includes:

  • Shopping basket
  • My account
  • Language/Locale selection
  • Checkout
  • Product list (‘catalogue’) pages
  • Product detail pages
  • Newsletter signup
  • Search

When setting up test automation, we want to have a very clear goal defined for both individual test cases and critical functionality/features. With respect to the list of functions above, the goal for each is roughly the same for each eCommerce site we review.

For example, shopping basket functionality can be described as a feature like this:

Feature: Shopping basket
  As a visitor of the ecommerce website
  I want to have a shopping basket
  So that I can see the products and costs of what I want to purchase

Best practice for Cucumber scenarios is to describe behaviour rather than actions. When we apply this to a specific shopping basket test scenario, we get this:

  Scenario: basket01 - Opening the shopping basket
    Given I have added an item to my shopping bag
    When I click the shopping bag icon
    Then I land on the shopping bag page
    And I can see the product in my shopping basket

  Scenario: basket02 - Adding a product to basket
    Given I am on a product detail page
    When I select the size/colour/quantity
    And I click the add to basket button
    Then the product is added to my shopping basket

This shopping basket scenario is valid for most eCommerce sites. When we look at the other features we have listed, we find we can describe a standard set of Cucumber test cases for each function which are valid for most eCommerce websites. We have created this eCommerce test suite written in Gherkin you can use for free.

For convenience, a small portion of this test suite has been automated for a well known eCommerce site. We have set it up in a way that one test scenario is environment, browser and locale/language independent. The scenario will, for example, be able to run in the Firefox browser on a staging environment in the English language, while at the same time work for a Dutch website on the test environment with the Chrome browser.

Cucumber and Gherkin are our favourite open-source tools, and because of that we have written a whole lot about Cucumber and Gherkin over the years. So much that we’ve created a separate blog category page where you can all of our articles talking about Cucumber and Gherkin. Have a look.

We hope you find this interesting!

Author: Mark Barzilay

Graduated with honors from TU Delft in 2007 studying Electrical Engineering and Media & Knowledge Engineering. Founded spriteCloud in 2009 and worked on test automation ever since, helping out small and large companies with their test automation strategy and infrastructure. Mark is also leading the development on Calliope.pro, an online platform for all your automated test results.

We’re spriteCloud, a leader in software and cybersecurity testing.

Aside from interesting articles, we also have a team of software testers that can help your organisation.

Have a look at our testing solutions.