Ali Abdylqawi
Ali Abdylqawi

Reputation: 1

is this a good gherkin syntax

This is my first time writing a gherkin scenario, and I'm wondering if my writing is appropriate for gherkin or not? The example is for getting to the dashboard. Here is my example:

Feature: [The dashboard of the platform]

Scenario: [getting into the dashboard]
Given user logged in 
When user clicks on the dashboard 
Then user get into the dashboard
When user clicks on my courses 
Then user sees the courses he got enrolled 
When user clicks on my marks
Then user sees his marks
When user clicks on my educational bags
Then user sees his videos and assignments 
When user clicks on my certificates 
Then user sees his certificates 
When user clicks on student record
Then he user sees his record
When user clicks on sign out
Then user logs out

Upvotes: 0

Views: 553

Answers (1)

diabolist
diabolist

Reputation: 4099

The art of writing good Gherkin is to focus on WHAT you are doing and avoid anything to do with HOW you are doing something. So with your scenario you need to think about WHAT you are doing.

Each scenario should deal with only one thing. So you should have only one WHEN per scenario.

Scenario: View my dashboard
Scenario: View my courses
Scenario: View my marks
Scenario: View my bags
...

Each scenario should be short and simple e.g.

Scenario: After I login I see my dashboard
  Given I am registered
  When I login
  Then I should see my dashboard

Notice how there is nothing in the scenario about clicking, filling in login details, or being registered.

Cucumber is designed for doing BDD. Behaviour Driven Development. So you start from the When which describes the new behaviour you are going to develop. Then you think about the Then, which describes the results you should see after you have done the new behaviour. Finally you think about the Given which is all about what you need to have done previously so you can do the When.

So for you next scenario viewing courses you would start with

Scenario: View my courses
  When I view my courses

then you would move onto

Scenario: View my courses
  When I view my courses
  Then I should see my courses

and finally for the Given you need to be viewing your dashboard so.

Scenario: View my courses
  Given I am viewing my dashboard
  When I view my courses
  Then I should see my courses

Each new piece of behaviour builds on existing pieces of behaviour.

Viewing courses builds on viewing the dashboard Viewing the dashboard builds on login Login builds on registration

Hopefully this provides a good start.

Upvotes: 1

Related Questions