Pre-requisite Scenario?

49 views
Skip to first unread message

Samuel Benison

unread,
Aug 14, 2020, 10:02:59 PM8/14/20
to getgauge
Hi guys,

I have a small question.

Is there a way to link the previous scenario to the current scenario and continue the current scenario only if the previous scenario passed?

For example, I have two scenarios (Scenario1 and Scenario2) in a spec file, and I don't want the Scenario2 to execute if any of the Steps in Scenario1 failed.

Is there any way to check the status of Scenario1 runtime and execute Scenario2 based on the result? Maybe I can add the first step to check status?

Please let me know your thoughts.

Thanks,
Samuel Benison

Vinay Shukla

unread,
Aug 17, 2020, 2:41:16 AM8/17/20
to getgauge
Hi Samuel,

Ideally, your scenarios should be independent of each other, so that they could also be run standalone. If a scenario has a dependency on another scenario, merging them should be considered.
Being said that, if it still is required you could check the current scenario status in `AfterScenario` hook using the `ExecutionContext` store status of that scenario in `SpecDataStore` and then access that in the `BeforeScenario` hook of later scenario. The scenario and hooks could be tagged so specific hook runs only for specific scenarios.

Noe that It's just a workaround, the result can be tricky sometimes. Since `AfterScenario` hook is also part of the scenario. of the hook fails, the scenario actually failed but the status set in the store might say it passed.

Regards
Vinay

Samuel Benison

unread,
Aug 17, 2020, 3:53:15 AM8/17/20
to getgauge
Hi Vinay,

Thank you so much for your response. I really appreciate it. I have a couple of follow up questions:

Do you know where I can find more documentation about ExecutionContext? I found the basic information here but I am trying to find all the options that the 'context' parameter can offer in the hook. For Scenario status, will that be `context.status`?

Also, Will the suggested workaround work when the order of the Scenario is not guaranteed? I read in the FAQ, that the order is not guaranteed if I run in parallel mode. I can avoid parallel mode, and try to use serial mode for the specs with dependent scenarios. So, my question is, will the order of scenario always maintained if I run a spec file in serial mode? How about when I execute using tags?

For example, Let's say I have a spec file with the below scenarios and tags:

Scenario 1 : Tag A
Scenario 2 : Tag B
Scenario 3 : Tag A

If I run the spec file for `Tag A`, will Scenario 1 always run before Scenario 3?

Please let me know your thoughts.

Thanks,
Sam 

Vinay Shukla

unread,
Aug 18, 2020, 6:39:42 AM8/18/20
to getgauge
Hi Sam,


> Do you know where I can find more documentation about ExecutionContext?
It is documented here. But I'm afraid it might not be very informative. You could create as Issue for updating the docs for the same at https://github.com/getgauge/docs.gauge.org. Maybe you could print the context to see what all the things are available or look at the code here. If you are using java the java docs can help you. For other languages, there are similar methods/properties according to the language semantics,.

> For Scenario status, will that be `context.status`?

There is no such field. the context has fields like `specification`, `scenario`, and `step` (the currently running one), then each the fields have fields like `name`, `filename`, `is_failing`, `tags`, `error_message` and `stacktrace` accordingly. Please look the code for more info. 

> Will the suggested workaround work when the order of the Scenario is not guaranteed?
As I said earlier it's a workaround, we have not tried it. So you have to try it yourself.

IMO it’s best to avoid the workaround and make the tests independent of each other as Gauge is not built with the workaround in mind and will be unpredictable. 

Thanks
Vinay
Reply all
Reply to author
Forward
0 new messages