Restaurant Part 6 – Detailed Testing

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

Overview

This deals with the testing of the Restaurant web application. In this section we will look at the detailed sample scenarios that are included in the two projects – Spring DI and Pico Container.

We will be using Cucumber-JVM for testing scenarios. Selenium will used for browser automation and AssertJ for assertion. WebDriverManager will be used for downloading the appropriate driver jar. Chrome browser is used, but this can be changed by modifying the source. AspectJ is used to manage the navigation between various screens. Spring and Pico Container will be used for dependency injection in the respective projects.

The test source for the Spring test project can be found here. The test source for the Pico Container test project can be found here. The scenarios are the same and code are pretty similar.

Feature Files

The scenarios mainly deal with the life cycle of the order and the effect of order modifications on a separate browser instance. The scenarios handling the first case are present in the following feature files – emptytable, orderedstatus, preparingstatus and readyservedstatus. The second case scenarios are mentioned in the syncorderchanges feature file. These are available for Spring at this location and for Pico Container at this location.

Running the Tests

Download the test code from the respective locations – Spring & Pico Container.

The test code requires POJO from the project source. These are available in the restaurant-entity.jar and is available in the test code. This jar needs to be installed in the local repository by using the following command.

mvn install:install-file -Dfile=<path-to-jar>\restaurant-entity.jar -DgroupId=restaurant.entity -DartifactId=restaurant-entity -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true

The restaurant Spring boot application jar needs to be downloaded from this location. The following command needs to be executed to start the web application.

java -Dspring.profiles.active=test -jar restaurant-boot.jar

The scenarios can be run by executing the POM using a command like ‘mvn install’.

Test Data

The test data for running the complete test suite is created on application startup by using the ‘test’ profile. The data details are stored in a json file. The mapping between the data and the scenario is defined by a tag with the “@Table” prefix.

Screen & Frame Navigation

The home page is divided into 3 iframes – table list, order display and search. The navigation of the driver between the home page iframes, kitchen and server pages is managed by AspectJ before method advice. The SwitchPageFrameAspect aspect class manages this (Spring & Pico). The advice is enabled for all public methods of the relevant pageobjects.

PageObjects

The pageobjects all inherit from the abstract BasePageObject (Spring & Pico). This contain the driver instance and frame switcher instance which contains the value of the screen handles. It has a switchScreen method which manages the driver navigation. The pageobjects for the iframes in the home page extend the abstract HomeFramePageObject (Spring & Pico) which extends the BasePageObject.

Spring Source

The Spring configuration class (Config) can be found here. It is annotated with the Configuration, ComponentScan with the pages package value and EnableAspectJAutoProxy annotation. It also contains methods for initializing the various driver beans. The driver instance is reused across scenarios.

The hooks are located in the DataSetup class. The Before hook manages the mapping of the scenario to the table which is mention in the scenario tag starting with the ‘Table’ prefix. The After hook closes the tabs opened in the course of scenario execution.

Pico Container Source

The hooks and driver initialization are located in the DataSetup class. The Before hook manages the mapping of the scenario to the table which is mention in the scenario tag starting with the ‘Table’ prefix and the driver initialization. The After hook closes the tabs opened in the course of scenario execution. The driver instance is reused across scenarios.

Leave a Reply

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