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.
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
- Product list (‘catalogue’) pages
- Product detail pages
- Newsletter signup
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 and it can can be found here:
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.
We hope you find this interesting!