-2

This is my first attempt in writing a scenario that has multiple possible outcome. Currently the scenario covered for the happy flow. However the scenario failed due to different status detected. Getting the dynamic value (Pass and Failed) during run time.

Then statement look like this which is happy flow :

Feature: Student exam score


 Scenario: Check exam score for 3 students and all students pass

 Given there are 3 students sit for examination

 And all the student completed then exam

 When teacher completed marking the exam paper

 Then studentA exam score is Pass

 Then studentB exam score is Pass

 Then studentC exam score is Pass

The actual execution can lead to this combination of outcome :

1.studentA:Pass , studentB:Pass , studentC:Failed

2.studentA:Pass , studentB:Failed , studentC:Pass

Scenario: Check exam score for 3 students and 2 student pass studentB failed

 Given there are 3 students sit for examination

 And all the student completed then exam

 When teacher completed marking the exam paper

 Then studentA exam score is Pass

 Then studentB exam score is Failed

 Then studentC exam score is Pass


Scenario: Check exam score for 3 students and 2 student pass studentC failed

 Given there are 3 students sit for examination

 And all the student completed then exam

 When teacher completed marking the exam paper

 Then studentA exam score is Pass

 Then studentB exam score is Pass

 Then studentC exam score is Failed

So currently looking for alternatives what is the best to handle this scenario with multiple outcome.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
xar3f
  • 1
  • 3
  • 1
    Please share your code so we can better understand your question – Les Nightingill Oct 18 '21 at 03:51
  • edited the post to include the code – xar3f Oct 18 '21 at 07:36
  • there still is no code – Max Oct 18 '21 at 08:13
  • What are your inputs? What are your outputs? What do you expect your outputs to be? – Max Oct 18 '21 at 08:15
  • 1
    Do you want to know how to write a single Scenario that captures either of two possible combinations of input? In which case, you may want to read up on [Scenario Outlines](https://cucumber.io/docs/gherkin/reference/#scenario-outline) - pass a table of data and it will run multiple times with different inputs and outputs. – JohnP Oct 18 '21 at 10:54
  • are your scenarios passing? – Les Nightingill Oct 19 '21 at 03:44
  • You have to change your step to accept the status as string. Then you can use data tables. You can check [this](https://www.javatpoint.com/data-table-in-cucumber) for using data table – HamzaFarooq Oct 20 '21 at 06:56

1 Answers1

1

You have to write your scenario like this Your feature file

Scenario: Check exam score for 3 students
Given there are 3 students sit for examination
And all the student completed then exam
When teacher completed marking the exam paper
And student exam score is "<StudentA>"
And student exam score is "<StudentB>"
And student exam score is "<StudentC>"

Example:
|StudentA   |StudentB   |StudentC   |
|Pass       |Pass       |Pass       |
|Pass       |Failed     |Pass       |
|Pass       |Pass       |Failed     |

and in your steps file

@When("^student exam score is \"([^\"]*)\"$")
public void student_exam_score_is_something(String statusStr) 
throws Throwable {
    if(statusStr.equals("pass"){
        // your code for passed student
    }
    else if(statusStr.equals("failed"){
        // your code for failed student
    }
}
HamzaFarooq
  • 429
  • 1
  • 4
  • 16