Feature Files and Scenarios - ChrisMell/OEL-wiki GitHub Wiki

Creating a Feature File

In the src/test/resources/features directory, navigate into the folder for the iteration you are working in and create a new file. Use the .feature extension when naming it. On the first line, add the tag for the iteration in the form @i#, where the # symbol is the iteration number. On the second line, write Feature: followed by a descriptive name of the feature file.

The file should look like this

@i#
Feature: Descriptive Name of the Feature File

Background

The Background keyword can be added after the Feature keyword. It should be used when you have multiple scenarios in the same feature file and they all require the same steps to be run first before the rest of the test case can be executed. This is perfect for running your initialization steps, i.e. navigating to the web page and logging in.

The full background should look like this

Background: Initialize the Test Before the Scenario
    Given user does this first
    When user does this second
    Then user does this third

Scenario

The Scenario keyword indicates the start of your test case. The gherkin steps go on the lines following this keyword.

Scenario: Descriptive Name
    Given user does this first
    When user does this second
    Then user does this third

Scenario Outline

The Scenario Outline keyword is useful for building a scenario that is run multiple times in order to test multiple inputs instead of having multiple scenarios that are almost identical. For example, if you need to test multiple input/output pairs in the same application, a scenario outline would be ideal. Scenario outlines also need to have an Examples table at the end of the Gherkin steps that contain the names of the variables and the values you need for the test case.

Instead of having three scenarios like this:

Scenario: First Scenario
    Given user does this step
    When user uses value first
    Then user sees the result 1st

Scenario: Second Scenario
    Given user does this step
    When user uses value second
    Then user sees the result 2nd

Scenario: Third Scenario
    Given user does this step
    When user uses value third
    Then user sees the result 3rd

You can have one scenario outline like this:

Scenario Outline: Both Scenarios in One
    Given user does this step first
    When user uses value <parameter1>
    Then user sees the result <parameter2>
    Examples:
      |parameter1|parameter2|
      |  first   |   1st    |
      |  second  |   2nd    |
      |  third   |   3rd    |
⚠️ **GitHub.com Fallback** ⚠️