Global hooks in Serenity BDD

感情迁移 提交于 2020-12-13 11:09:06

问题


I was trying to implement global hooks in serenity-bdd project. As I browse through found below links and none of them worked for me. Some of them not specific to Serenity-BDD though.

package mypackage;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        features = "src/test/resources/features",
        glue = {"MyProj.cucumber.stepdefinition"},
public class MyTest {

         @Before
         public static void setUp() {
                 //do something here
         }

}

Solution 1

Solution 2

My Maven versions are:


回答1:


I am not sure I caught your purposes and what you want to do before the test execution. Since you use the Serenity framework I suggest you look at StepListener implementation. It uses Java SPI. Probably it will be useful to you in your task.

In a few words:

Serenity has class StepEventBus which has the logic to load service implementation from classpath before the test execution. You need only to implement your custom StepListener and override methods. And after that, you will be able to run your peace of code on different run stages(feature start, test start, step start, etc.)



来源:https://stackoverflow.com/questions/61815030/global-hooks-in-serenity-bdd

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