Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cucumber Repeat steps

I am learing cucumber and trying to write a feature file.

Following is my feature file.

Feature: Doctors handover Notes Module

Scenario: Search for patients on the bases of filter criteria
Given I am on website login page
When I put username, password and select database:
  | Field        | Value        |
  | username     | test         |
  | password     | pass         |
  | database     | test|
Then I login to eoasis
Then I click on doctors hand over notes link
And I am on doctors handover notes page
Then I select sites, wards, onCallTeam, grades,potential Discharge, outstanding task,High priority:
  | siteList      | wardsList                     | onCallTeamList   | gradesList | potentialDischargeCB | outstandingTasksCB | highPriorityCB |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | null             | null       | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | null       | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | true               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | true               | true           |
Then I click on search button
Then I should see search results

I want to repeat last three steps like I select the search criteria then click on search button and then check search result. So how should I break this feature file. if I use scenario outline then there would be two different scenarios One for login and one for search criteria. Is that fine? Will the session will maintain in that case? Whats the best way to write such feature file.

Or is this a right way to write?

like image 503
Harry Avatar asked Mar 17 '23 16:03

Harry


2 Answers

I don't think we can have multiple example sets in a Scenario Outline. Most of the scenario steps in the example is too procedural to have its own step. The first three steps could be reduced to something like.

Given I am logged into eoasis as a <user>

Code in the step definition, which could make calls to a separate login method that could take care of updating entering the username, password and selecting database.

Another rule is to avoid statements like "When I click the doctor's handover link". The keyword to avoid here being click. Today its a click, tomorrow it could be drop down or a button. So the focus should be on the functional expectation of the user, which is viewing the handover notes. So we modify this to

When I view the doctor's handover notes link

To summarize, this is how I would write this test.

Scenario Outline: Search for patients on the basis of filter criteria
Given I am logged into eoasis as a <user>
When I view the doctor's handover notes link
And I select sites, wards, onCallTeam, grades, potential Discharge, outstanding task, High priority
And perform a search
Then I should see the search results

Examples: 
|sites          |wards                          |onCallTeam        |grades      |potential Discharge   |outstanding task    |High priority|
| THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | null             | null       | null                 | null               | null        |
like image 63
roonie Avatar answered Mar 28 '23 01:03

roonie


This really is the wrong way to write features. This feature is very declarative, its all about HOW you do something. What a feature should do is explain WHY you are doing something.

Another bad thing this feature does is mix up the details of two different operations, signing in, and searching for patients. Write a feature for each one e.g.

Feature: Signing in
  As a doctor
  I want my patients data to only be available if I sign in
  So I ensure their confidentiality

Scenario: Sign in
  Given I am a doctor
  When I sign in
  Then I should be signed in

Feature: Search for patients
  Explain why searching for patients gives value to the doctor
  ...

You should focus on the name of the feature and the bit at the top that explains why this has value first. If you do that well then the scenarios are much easier to write (look how simple my sign in scenario is).

The art of writing features is doing this bit well, so that you end up with simple scenarios.

like image 29
diabolist Avatar answered Mar 28 '23 02:03

diabolist