You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature: Viewing the home page
In order to see all the cool stuff
I should be able to visit the home page
Background:
Given I am not logged in
Scenario: not logged inWhen I view the home page
Then I see the page
Scenario: viewing / on a mobileWhen I view the home page from an iphone
Then I am redirected to the mobile page
Scenario: viewing / on a mobile with redirect-to-mobile=noWhen I view the home page from an iphone specifying redirect-to-mobile=no
Then I am not redirected to the mobile page
And I see the page
Scenario: viewing the mobile version with an upcoming event, a past event and a postGiven there is an upcoming event
And there is a past event
And there is a post
When I view the mobile version of the home page
Then I see the page
Scenario: viewing the mobile version without any events or postsWhen I view the mobile version of the home page
Then I see the page
The problem that sometimes not every scenario have the same background in a feature. So some of them need a logged in state, while some of the need a not logged in state. Afaik. there is no support to reuse such code. Probably split into multiple features, but I thought it would be better to use groups:
Feature: Viewing post pages
In order to absorb Lachlan's deep insights into man and machine
I should be able to visit pages and pages and pages of blog posts
Group:
Background:
Given I am logged in
Scenario: viewing a post when logged inWhen I view the post page
Then I see the page
Scenario: viewing a mobile post when logged inWhen I view the mobile post page
Then I see the page
Scenario: viewing a mobile post when not logged inWhen I view the mobile post page
Then I see the page
Group:
Background:
Given I am not logged in
Scenario: viewing a post when not logged inWhen I view the post page
Then I see the page
By some of the cases this hierarchical grouping won't work, so this is not a perfect solution. Tagging would be perfect, but I am unsure whether I should use it in this cases. Any opinion?
Another possible solution to match the "when not logged in" part from the scenario text using a helper that adds the Given I am not logged in. So the code would be such simple:
Feature: Viewing post pages
In order to absorb Lachlan's deep insights into man and machine
I should be able to visit pages and pages and pages of blog posts
Scenario: viewing a post when logged inWhen I view the post page
Then I see the page
Scenario: viewing a mobile post when logged inWhen I view the mobile post page
Then I see the page
Scenario: viewing a mobile post when not logged inWhen I view the mobile post page
Then I see the page
Scenario: viewing a post when not logged inWhen I view the post page
Then I see the page
I am not sure whether this is possible by the current test runner.
The text was updated successfully, but these errors were encountered:
ghost
changed the title
Grouping scenarios by background (feature request)
Reusing different backgrounds
May 23, 2015
I haven't put much thought in it but the Group: keyword is interesting and deserves some thoughts. Matching the scenario name seem too error-prone to me (but you can achieve that in a before hook in your own suite).
@Inf3rno Can you reopen this on the gherkin3 repo please?
I am currently learning cucumber and I was checking some examples here: https://github.com/webjam/webjam/tree/master/features
Most of the scenarios contains
Given I am not logged in
or
Given I am logged in
so this is a clearly reusable part of the features.
According to the documentation it should be moved to a Background e.g. by https://github.com/webjam/webjam/blob/master/features/home.feature
The problem that sometimes not every scenario have the same background in a feature. So some of them need a logged in state, while some of the need a not logged in state. Afaik. there is no support to reuse such code. Probably split into multiple features, but I thought it would be better to use groups:
By some of the cases this hierarchical grouping won't work, so this is not a perfect solution. Tagging would be perfect, but I am unsure whether I should use it in this cases. Any opinion?
Another possible solution to match the "when not logged in" part from the scenario text using a helper that adds the
Given I am not logged in
. So the code would be such simple:I am not sure whether this is possible by the current test runner.
The text was updated successfully, but these errors were encountered: