tosha tosha - 1 year ago 142
Java Question

Cucumber-JUnit, is there a way to control the order in which @before and @after tags run

I have two @after tags, @close-browser and @screenshot.So, right now when I use both tags for feature file it is first executing @close-browser and It fails in executing after method for @screenshot.
Is there a way that I can tell cucumber to run @screenshot after method first?

Answer Source

The screenshot should be taken in one of the @After annotated methods. Like this:

public void finish(Scenario scenario) {
    try {
        byte[] screenshot =
        scenario.embed(screenshot, "image/png");
    } catch (WebDriverException somePlatformsDontSupportScreenshots) {

    finally {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download