how to continue with next scenario in case of a Failure

2,061 views
Skip to first unread message

Styris

unread,
Jan 15, 2016, 9:16:20 PM1/15/16
to Cukes
Hello friends,

I am using the Cucumber (JAVA) framework for my automation testing and have carefully designed my scenarios so that after each scenario the user is logged out. 1 Feature file has multiple scenarios...and each scenario starts with a clean slate, and is independent of any scenario. I did this mostly so that if one scenario fails..the tests will continue to run with the next scenario; so that every scenario does not fail. (FYI I have multiple feature files...and each file has multiple scenarios)
However even with my current approach if one test fails the rest fail. For e.g. If User tries to compose a message and that compose button is corrupted and for some reason the test fails...it moves to the next test but since the next test starts with logging into the app...that next test also fails since the current screen is the compose button screen, not the log in screen.

How can I, if it is even possible, make sure that if one test fails the rest do not fail ? Please advise.

Thank you!

Paolo Ambrosio

unread,
Jan 16, 2016, 5:20:46 AM1/16/16
to cu...@googlegroups.com
On Sat, Jan 16, 2016 at 2:16 AM, Styris <kashi...@gmail.com> wrote:
> Hello friends,
>
> I am using the Cucumber (JAVA) framework for my automation testing and have
> carefully designed my scenarios so that after each scenario the user is
> logged out.

Scenarios should not specify that the user logs out, since that is a
technical detail. You should use hooks for this kind of behaviour.

> 1 Feature file has multiple scenarios...and each scenario starts
> with a clean slate, and is independent of any scenario. I did this mostly so
> that if one scenario fails..the tests will continue to run with the next
> scenario; so that every scenario does not fail. (FYI I have multiple feature
> files...and each file has multiple scenarios)
> However even with my current approach if one test fails the rest fail.

After hooks are always executed, even if the scenario fails.

> For
> e.g. If User tries to compose a message and that compose button is corrupted
> and for some reason the test fails...it moves to the next test but since the
> next test starts with logging into the app...that next test also fails since
> the current screen is the compose button screen, not the log in screen.
>
> How can I, if it is even possible, make sure that if one test fails the rest
> do not fail ? Please advise.

import cucumber.api.java.After;

...

public class ... {

@After
public void signOutUser(Scenario scenario) {
// TODO sign out your user here
}
}

> Thank you!

Andrew Premdas

unread,
Jan 16, 2016, 8:00:35 AM1/16/16
to cu...@googlegroups.com
This should not be happening. A canonical idea behind testing is that each scenario/test should be independent. However this doesn't mean that any error with the system will only cause one scenario to fail. For example if you have 50 scenarios for Users who have logged in, and you break logging in you will get 50 failed scenarios. This is normal, you fix the first one and then run the others again to see if they now work.

If, in your particular test suite, this behaviour does not happen, then I'd expect that someone has done something clever and stupid to change this behaviour, probably using hooks. Just to clarify lets say we have two scenarios

Given I am Fred
When I login
Then I should be logged in

...

Given I am Bill
When I login
Then I should be logged in

1. You should not need to do anything to logout Fred or Bill
2. No matter what order these scenarios are run, they will always start with the user logged out e..g equivalent to

Given I am logged out
Given I am Fred
...

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Styris

unread,
Jan 20, 2016, 9:06:15 PM1/20/16
to Cukes
Thanks for your response. Nothing seems to be working for me. I cannot run a logout scenario as part of my @After because the logout is done through a particular screen..and if the tests are failing at some other screen..it will never be able to go to the screen where the user needs to log out so the @After would never be doable. So I have to have an @After hook that will do a driver.quit or driver.resetApp.
Problem is that if I do @After driver.quit and then a @Before for a new driver I get an error saying "remote browser may have died" or something to that effect. If I use @After driver.closeApp and @Before driver.launchApp() that does not work either as it says "another instruments session is around". If I do a @After of driver.closeApp() and driver.launchApp()..with no @Before hook then I get an error saying "Session ID is null. Using WebDriver after calling quit()?".

I have no clue how to handle this. FYI. I have a class which contains a method containing the driver: protected IOSDriver<IOSElement> getDriver(). All the other classes then just declare 'IOSDriver<IOSElement> driver = getDriver();'.

Please advise. Thanks!

Styris

unread,
Jan 20, 2016, 9:07:38 PM1/20/16
to Cukes
Thanks for your response. Nothing seems to be working for me. I cannot run a logout scenario as part of my @After because the logout is done through a particular screen..and if the tests are failing at some other screen..it will never be able to go to the screen where the user needs to log out so the @After would never be doable. So I have to have an @After hook that will do a driver.quit or driver.resetApp.
Problem is that if I do @After driver.quit and then a @Before for a new driver I get an error saying "remote browser may have died" or something to that effect. If I use @After driver.closeApp and @Before driver.launchApp() that does not work either as it says "another instruments session is around". If I do a @After of driver.closeApp() and driver.launchApp()..with no @Before hook then I get an error saying "Session ID is null. Using WebDriver after calling quit()?".

I have no clue how to handle this. FYI. I have a class which contains a method containing the driver: protected IOSDriver<IOSElement> getDriver(). All the other classes then just declare 'IOSDriver<IOSElement> driver = getDriver();'.

Please advise. Thanks!

On Saturday, January 16, 2016 at 2:20:46 AM UTC-8, Paolo Ambrosio wrote:

Styris

unread,
Jan 20, 2016, 9:16:03 PM1/20/16
to Cukes
correction 

If I do a @Afterof driver.closeApp() and driver.launchApp()..with no @Before hook then I get an error saying "after hook failure". If I do a @After of driver.quit()..with no @Before hook then I get an error saying "after hook failure". If I do a @Afterof driver.quit()..with no @Before hook then I get an error saying "after hook failure". If I do a @After of driver.quit()..with no @Before hook then I get an error saying "Session ID is null. Using WebDriver after calling quit()?".




On Saturday, January 16, 2016 at 2:20:46 AM UTC-8, Paolo Ambrosio wrote:
Reply all
Reply to author
Forward
0 new messages