Skip to content

General Gherkin Structure

Adam De Fouw edited this page Oct 19, 2021 · 17 revisions

Typical Scenario Structure in Terms of Gherkin Keywords

Given .... < condition >

When ... < action >

Then ... < assertion >

And ... < additional [assertions, actions, conditions] >

But ... < additional [assertions, actions, conditions] >

Multiple Conditions, Actions, Assertions

Thus, when you have multiple conditions, actions, or assertions in a row:

Given

Given .... < condition >

And ... < additional condition >

When

When .... < action >

And ... < additional action >

Then

Then .... < assertion >

And ... < additional assertion >

Concrete Examples

Given

Given I am an "admin" user who logs into REDCap

And I visit "/"

When

When I visit "Control Center"

And I click the link labeled "My Projects"

Then

Then I should see "Control Center"

And I should see "My Projects"

What is the difference?

Behind the scenes - Given, When, Then, And, But - they all work exactly the same!

Thus, the tests will still work regardless of which Gherkin keyword we use.

Choosing the correct keyword is a matter of readability and convention.

Conclusion?

It's better to write a test and get some of the keyword convention structure incorrect than to not write a test.

It's also often the case that these keywords need to change as a test evolves.

We can clean these keywords up easily after the steps of a test are determined.

Clone this wiki locally