Closed eprisacaru closed 6 years ago
This is the normal lifecycle. What do you need the browser for in the @After method?
Because in @after I'm doing the logout from the app.
From my point of view the browser should be restarted after the scenario and @after hooks is executed.
That would make sense, but it's not necessarily how the Cucumber lifecycles and Serenity integration works at the moment.
The @After hooks are managed on a different lifecycle, and the order cannot be controlled, so it would be hard to manage when the browser gets shut down.
Please feel free to take a look at the code and propose a PR
@After hooks can now be used within the normal scenario lifecycle, before the browser is closed.
@after hooks can now be used within the normal scenario lifecycle, before the browser is closed.
Hi @wakaleo , may I please ask how? What's the syntax/parameter/switch to control this? Thank you very much.
The same way you refer to a driver in any other part of the test code.
Hi @wakaleo , thank you very much for your quick reply. I just read your second last message again. I think now I fully understand what you mean. Yes, using driver in @after hook in "normal scenario lifecycle" has no problem, I can do clean up step (deleting test record) in it. But when test scenario fails, then the browser is closed. Even though @after hook is still called, but it has no access to browser any more. Is this supposed to be the case? My code snippet of using @after hook is as below:
`public CucumberHooksSteps() {
After("@memberForm", () -> {
Set<String> ids = user.getContributionIds();
if (!ids.isEmpty()) {
System.out.println(">>>>>> Clean up step is called to delete: "+ids);
contrHistoryPage.open();
contrHistoryPage.deleteContrRecord(ids);
}
});
}`
I have a serenity + cucumber project for a web application and I'm using this property serenity.restart.browser.for.each=scenario. And I have in CucumberHooks class an @After method which is executed after each scenario.
The issue is that the browser is restarted before the @After method is executed.
Is there something that I'm doing wrong?
I'm using: