0

I am using a Cucumber feature file with two scenarios using Scenario Outline. Is there a way to execute the second Scenario Outline, only if the first one passes? Scenario Outline: Test 1 fails, then Scenario Outline: Test 2 is never executed.

I wonder if there are some tags that may work like @BeforeTest that i can apply before Scenario Outline: Test 2 only. But then i have to find a way to listen for the failure in Scenario Outline: Test 1

Structure of the feature file is as follows:

 Scenario Outline: Test 1
 Given i run test one
 When test one passes 
 Then run test 2

 Scenario Outline: Test 2
 Given test one passes
 When i run test two successfully
 Then both tests pass

Thank you!

kokodee
  • 285
  • 1
  • 3
  • 15

1 Answers1

1

This is not recommended / supported.

From the Cucumber FAQ:

"Each scenario should test one thing and fail for one particular reason. This means there should be no reason to skip steps.

If there does seem to be a reason you’d want to skip steps conditionally, you probably have an anti-pattern. For instance, you might be trying to test multiple things in one scenario or you might not be in control of the state of your test environment or test data.

The best thing to do here is to fix the root cause."

Marit
  • 2,399
  • 18
  • 27
  • all that you posted is true and this is exactly how my tests are structured. Each Scenario Outline is an individual test. In many cases, placing two or more Scenario Outlines makes sense when the functionality of the tests is related. But what i am trying to achieve is save test execution time. For me, it doesn't make sense to run Scenario Outlines 2 or Scenario Outlines n within a feature file, knowing that Scenario Outlines 1 failed, which will make Scenario Outlines 2..n fail as well.. In this instance i can save that test execution time and this is my main goal here. – kokodee Oct 07 '19 at 18:10
  • Each scenario outline is essentially a separate test though. If the fact that scenario 1 fails, means that scenario 2 etc will also fail, what is their added value? – Marit Oct 07 '19 at 20:18
  • Yes, my feature files are structured to test page by page and e2e. While each Scenario Outline (SO) is a separate test, all SOs, relevant for that page or module of the application, are placed within same feature file. The value of this approach is exactly what i am asking here, If i know that a common flow for all tests fail within a previous execution, i can save execution time by not running the rest of the SOs. So, one way to achieve that is to write each SO test result in a file and read it before running the next one, but it would be great if the framework supported that. – kokodee Oct 09 '19 at 03:57
  • except for Cucumber is an opinionated framework and is of the opinion that your tests should be independent. – Marit Oct 09 '19 at 10:20
  • Hmm, i don't follow you on your last comment. By definition: Scenario Outline keyword can be used to run the same Scenario multiple times, with different combinations of values. Reference: https://cucumber.io/docs/gherkin/reference/#scenario-outline – kokodee Oct 09 '19 at 15:35
  • "We can collapse these two similar scenarios into a Scenario Outline." ; each is a separate test/scenario. They will also be compiled into separate tests/scenarios. The framework does not support your use case. – Marit Oct 10 '19 at 10:46