Advanced Gherkin Techniques
In addition to the basic Gherkin keywords that are required to define a Feature, Eggplant Functional (EPF) lets you take advantage of some additional keywords for more complete control over your Gherkin tests. These advanced Gherkin topics include the following, each of which is described in detail below:
For basic information about creating a Gherkin Feature in Eggplant Functional, see Creating Tests with Gherkin.
Backgrounds
A Background element can be used to define any Given steps that are consistent across every Scenario in a Feature. The Background is placed before the first Scenario in the Feature, and can include any number of Given statements. You can also use the And or But keyword aliases in place of Given.
An example Background definition might look like the following:
Background: app in focus
Given that the Calculator app is running
And that the app is in focus
When you run a Feature that includes a Background element, the Given steps outlined in the Background are run for each Scenario as it is run so that you don't need to include the steps within each Scenario.
Scenario Outlines
If you have a test case where you want to perform the same action multiple times with variable values, you can use a Scenario Outline instead of repeating a standard Scenario with hard-coded values. The Scenario Outline element lets you parameterize values within steps, and then reads values from a data table in a section titled Examples that follows it.
The steps you include within the Scenario Outline are the same as for a regular Scenario, as outlined in Definition of a Feature: Given, When, Then (including the And/But aliases as necessary). The variables are strings that you enclose in angle brackets, <var1>. You can include a variable on any step.
A Scenario Outline in a Feature might look like the following:
Scenario Outline: check multiplication function on Calculator app
Given that the Calculator app is running and in focus
And there is no current value in the calculator
When I multiply <Number1> by <Number2> in the calculator app
Then the app displays the correct <Answer>