How to write automated tests using Cucumber (2/7)

Photo by Natalie Rhea Riggs — Unsplash
Branches represent tool on different steps of readiness, according to the articles list.

Software requirements

We will use Java 8 programming language provided via Amazon Corretto and Maven 3.6.3.

Cucumber plugin for the IntelijIdea

My recommendation, is install this plugin first.

Project setup

Create new maven project:

Select menu New — Project
Select Maven and press Next

Dependencies configuration

Then we need to add Cucumber dependencies to the project. Open pom.xml file located on your project folder:

Cick Reimport button

Package structure

The are no rules how packages structure should looks like. We will create two folders, features and steps. Inside this folders you can create any subfolders
to structure your code (we will do it later for the API and Web tests).

Created packages

TestNg runner

We will implement testNg runner for the Cucumber tests. This file will be executed by maven, provide configuration to the Cucumber and start execute feature files.

Catalog with the test configuration

Most of the time automated tests will be executed on systems placed across different environments. We will create a folder with the configuration files for the different environments and with the test run commands will provide
a parameter to choose configuration file to read.

host=https://dev.example.com" to the dev.properties;
host=https://qa.example.com to the qa.properties;
host=https://example.com to the prod.properties;

Test Configuration class and Run configuration

We need a class which will be read and store all parameters from
the configuration file, depends on the “environment” parameter.

Test Initialization

Before the first test will be executed, we need to perform test initialization actions, like reading configuration file and initializing HTML report file.

First feature file

Finally, we are ready for the writing the first Cucumber feature file. For the Gherkin and Cucumber tutorials I suggest official Cucumber documentation.

Add glue code

Create class SystemInfoSteps:

Execute the tests

The final version of the execution tool after all manipulation stored here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store