After Step and before Step Cucumber

本秂侑毒 提交于 2020-02-05 02:03:09

问题


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.


回答1:


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




回答2:


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
    }

}



回答3:


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



来源:https://stackoverflow.com/questions/47671078/after-step-and-before-step-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!