Steps from the Background cannot be combined with Examples. Is it a limitation with Behat.
I have the following feature file.
Background:
Given I have the login Page
When I login to the application using "<username>"
Then the list is displayed
When I select an item from the list
Then I am taken to the Dashboard
When I navigate to the Overview Page
Then the Overview Page is displayed
@javascript @frontend @devlocal
Scenario Outline: To verify the Overview page content
Then overview page main headings are displayed
Examples:
| username | role |
| RoleUser | ROLE_USER |
| RoleAdmn | ROLE_ADMIN |
This produces the error:
[Behat\Gherkin\Exception\ParserException]
Expected Comment or Scenario or Outline or Step token, but got Examples on line: 15 in file: /var/Features/Overview.feature
The reason I have so many steps in the "Background" is because that is the logical flow to get to a page. And I have several scenarios using those steps.
I do have a working solution for this problem which is using all those steps from the "Background" within the "Scenario". This works absolutely fine. However I have 5 different scenarios for this feature and if I copy and paste the same steps within all the 5 scenarios it looks absolutely messy and cumbersome. I thought this was the main reason why we use Background section?
Here is what I'm using at the moment:
Background: Given I have the login Page
@javascript @frontend @devlocal
Scenario: To verify the Overview page content
When I login to the application using "<username>"
Then the list is displayed
When I select an item from the list
Then I am taken to the Dashboard
When I navigate to the Overview Page
Then the Overview Page is displayed
Then overview page main headings are displayed
Examples:
| username | role |
| RoleUser | ROLE_USER |
| RoleAdmn | ROLE_ADMIN |
Imagine having all those steps from the Scenario section for all the different scenarios