Restaurant Part 5 – Basic Testing – Spring Boot Web Application

This is the fifth part of the series. The links for the remaining posts are introductionapplication executionscreensinitial data, detailed testing.

Overview

This deals with the testing of the Restaurant web application. In this section we will look at the basic sample tests that are included in the project.

We will be using Cucumber-JVM for Behaviour-Driven Development testing purposes. Selenium will used for browser automation and AssertJ (available by default with spring-boot-starter-test) for assertion. Spring will be used for dependency injection, which is available by default along with the spring boot starter parent. WebDriverManager will be used for downloading the appropriate driver jar. Chrome browser is used, but this can be changed by modifying the source.

The test source for the application can be found here.

Order Creation Scenarios

We will be attempting to automate two test cases related to new order creation. First one is a successful order creation and the second, a negative test, an unsuccessful order without any dish selected.

Successful Order Creation

The user navigates to the homepage and selects a vacant table from the list in the left side. The user then selects dishes and quantities for the order from the main section. Order is then submitted by clicking on ‘CREATE Order’ button.

On submission an alert informs the user about the successful order creation.

The status of the table displays ‘ORDERED’, the details are displayed and the order is listed on searching with appropriate filters.

The order details are also available in the kitchen page under the ordered column.

This can be modeled as the below Cucumber scenario.

  Scenario: Create a successful order
    Given User navigates to home page
    When User selects vacant table
    And User creates new order by selecting dishes
      | dish                  | qty |
      | Fried Gnocchi         |   3 |
      | Margherita            |   1 |
      | Tagliatelle Bolognese |   4 |
      | Chicken Alla Diavola  |   2 |
    Then Alert is displayed with order creation message
    And Created order details should be displayed
    And Order should be available in Ordered status in search
    And Order status in table list should be Ordered
    And Order should be available in Ordered status in kitchen

Unsuccessful Order No Dish Selected

When an order is attempted without selecting any dishes or quantities then an error alert message is displayed. The table is in ‘VACANT’ status and no order is created.

This can be modeled as the below Cucumber scenario.

  Scenario: Create order without any dish
    Given User navigates to home page
    When User selects vacant table
    And User creates new order without selecting dish
    Then Alert is displayed with order creation warning
    And Order should not be created
    And Table should be vacant in table list

Test Execution with Spring Boot Maven Plugin

The scenarios can be executed with the help of Spring Boot Maven Plugin. The plugin when added to the pom, starts and stops the Spring Boot application around the integration tests. The Maven Failsafe Plugin needs to be added, to automatically execute the Cucumber runner. All that is needed is to run the pom with a command that includes the integration test, ‘mvn clean install‘ should suffice.

Test Execution with Cucumber Runner

The scenarios can also be executed by running the Cucumber Runner. First the application has to be started by navigating to the source folder which contains the restaurant-boot.jar. Use the following command to execute the jar, ‘java -jar restaurant-boot.jar‘. Then run the Cucumber runner as a test class.

Test Code Details

Cucumber-spring is used for managing the sharing of objects between step definition and pageobject classes. For more details refer to this article. The main classes are – spring boot configuration class, step definition class with @SpringBootTest annotation, pageobject classes with @Component annotation.

Leave a Reply

Your email address will not be published. Required fields are marked *