Selenium Cucumber Java BDD Framework 1 - Setup | Step by Step

preview_player
Показать описание
What is Cucumber in Selenium?
Cucumber Framework in Selenium is an open-source testing framework that supports Behavior Driven Development for automation testing of web applications. The tests are first written in a simple scenario form that describes the expected behavior of the system from the user’s perspective.

Step 1 - Create a new maven project
Step 2 - Add maven dependencies
Cucumber Java | Cucumber JUnit | JUnit | Selenium Java
Step 3 - Create a folder Features under src/test/resources
Step 5 - Download cucumber plugin from Eclipse Marketplace
Step 6 - Create feature file and add contents
Feature
Scenario
Steps
Scenario Outline
Example
Tags
Comments
Step 7 - Try to run the feature file
Step 8 - Add Step Definitions / Glue Code under src/test/java package
Step 9 - Create a Runner class

Cucumber BDD framework mainly consists of three major parts – Feature File, Step Definitions, and the Test Runner File.

Feature File
A standalone unit or a single functionality (such as a login) for a project can be called a Feature. Each of these features will have scenarios that must be tested using Selenium integrated with Cucumber. A file that stores data about features, their descriptions, and the scenarios to be tested is called a Feature File

Description: The user shall be able to login upon entering the correct username and password in the correct fields. The user should be directed to the homepage if the username and password entered are correct.

Gherkin keywords
Keywords such as GIVEN, WHEN, and THEN used to write the test in Cucumber are called Annotations.

Step Definitions
Now that the features are written in the feature files, the code for the related scenario has to be run. To know which batch of code needs to be run for a given scenario, Steps Definitions come into the picture. A Steps Definitions file stores the mapping data between each step of a scenario defined in the feature file and the code to be executed

Test Runner File
To run the test, one needs a Test Runner File, which is a JUnit Test Runner Class containing the Step Definition location and the other primary metadata required to run the test.

The Test Runner File uses the @RunWith() Annotation from JUnit for executing tests. It also uses the @CucumberOptions Annotation to define the location of feature files, step definitions, reporting integrations, etc.
Рекомендации по теме