serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

After hook is executed after the browser is closed #87

Closed eprisacaru closed 6 years ago

eprisacaru commented 7 years ago

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:

1.2.5-rc.1 1.1.28
wakaleo commented 7 years ago

This is the normal lifecycle. What do you need the browser for in the @After method?

eprisacaru commented 7 years ago

Because in @after I'm doing the logout from the app.

eprisacaru commented 7 years ago

From my point of view the browser should be restarted after the scenario and @after hooks is executed.

wakaleo commented 7 years ago

That would make sense, but it's not necessarily how the Cucumber lifecycles and Serenity integration works at the moment.

wakaleo commented 7 years ago

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.

wakaleo commented 7 years ago

Please feel free to take a look at the code and propose a PR

wakaleo commented 6 years ago

@After hooks can now be used within the normal scenario lifecycle, before the browser is closed.

IanHong66 commented 3 years ago

@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.

wakaleo commented 3 years ago

The same way you refer to a driver in any other part of the test code.

IanHong66 commented 3 years ago

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);
        }
    });
}`