问题
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