简体   繁体   中英

After Step and before Step Cucumber

I want to execute something before and after each step (not scenario). How do I do that in Cucumber ?

Like the after and before in junit.

** I am using java.

There should be something like AfterStep (haven't found BeforeStep yet)

AfterStep do #After every step #this is also before the next step... end

If you want to filter these for certain steps, do

AfterStep('@cucumis', '@sativus') do # This will only run after steps within scenarios tagged # with @cucumis AND @sativus. end

Reference: https://github.com/cucumber/cucumber/wiki/Hooks

In recent version of io.cucumber, both @AfterStep and @BeforeStep hooks are available,

import cucumber.api.java.AfterStep;
import cucumber.api.java.BeforeStep;

public class Hooks {

    @BeforeStep
    public void beforeStep() {
        System.out.println("======>  This is before step  <======");
        //Do something before executing the step
    }

    @AfterStep
    public void afterStep() {
        System.out.println("======>  This is after step  <======");
        //Do something after executing the step
    }

}

BeforeStep and AfterStep hooks are available in the latest cucumber jvm api. Just update your pom with the latest version for cucumber-jvm. For more information just go through the link below :

https://github.com/damianszczepanik/maven-cucumber-reporting/issues/100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM