Cucumber BDD Tests

Author tests using Cucumber BDD

So, far we have authored tests using TestNG. Cucumber BDD could be used to author tests too.

Plugin

Let’s first add cucumber plug-in to Intellij IDEA, if not installed already.

Dependencies

If you have created the project using EKAM template, then all the necessary dependencies will be already present in your repo. If not, please copy cucumber specific dependencies, tasks, args and execution rules from here.

Features

Creature features directory under your src/test/resources folder.

Step Definitions

Let’s create step definitions for this feature as shown below

Pages

Let’s create POM class with all locators and methods.

Build connection between POM and StepDefinitions

Now that we have created Page file, let’s call all the relevant methods of this class from our step definitions file. Create an object of POM inside your step definition file and call respective methods.

WebBaseStep

One more thing we need before we can run our test is base file which extends EKAM’s WebScenarioDefinition which does the magic of connecting all the components and scenario setup.

Execution using IDE

Select your feature file and run using cucumber plugin as shown below.

Execution from the command line

./gradlew runCucumberWebTests

Glue code

  • In case of any errors, please make sure you are pointing to correct steps folder as glue in your build.gradle as shown below
  • All the configs, report generation and data generation remains same like rest of the framework.

Reference

  • Above example can be found here