The BDD approach
Tests in this project follow a three-layer BDD flow:- Feature file — a
.featurefile written in Gherkin that describes behaviour in plain language - Step definitions — Java methods annotated with
@Given,@When,@And, or@Thenthat execute the Gherkin steps - Page objects — Java classes that encapsulate element locators and browser interactions for a specific page
The existing feature file
The project currently has one feature file atsrc/test/resources/features/RegistroRiu.feature:
RegistroRiu.feature
Given/When/And/Then line maps exactly to a method in RiuSteps.java. The @smoke tag marks this scenario for the default test run.
Adding a new scenario
Open or create a feature file
Place
.feature files inside src/test/resources/features/. You can add scenarios to an existing file or create a new one.src/test/resources/features/RegistroRiu.feature
Run the test to get pending step snippets
Run
mvn test after adding the new scenario. Cucumber will print an Undefined step warning to the console with the method signatures you need to implement:Add the step definition to the steps class
Open
src/test/java/steps/RiuSteps.java (or create a new steps class) and implement the method. Use the injected TestContext to access the WebDriver and construct page objects:src/test/java/steps/RiuSteps.java
Create a page object if needed
If the step interacts with a page that does not have a page object yet, create one. See Adding page objects for a full walkthrough.
Tagging scenarios
Tags annotate individual scenarios or an entireFeature block. The default runner in TestRunner.java is configured to run @smoke:
runners/TestRunner.java
| Tag | Intended use |
|---|---|
@smoke | Critical happy-path scenarios, run on every build |
@regression | Full regression scenarios, run before releases |
@wip | Work-in-progress scenarios, excluded from CI |
Running specific tags
Override the tag filter at runtime without changingTestRunner.java:
cucumber.filter.tags overrides the tags value in @CucumberOptions for that run only. The source code is not modified.Mapping Gherkin steps to Java methods
The step text in the feature file must match the annotation string in the Java method exactly (Cucumber treats it as a regular expression).Feature file
RiuSteps.java
{string}, {int}, and {word} capture groups to pass dynamic values from the Gherkin step into the method parameter: