我试图在serenity-bdd项目中实现全局钩子。当我浏览时,发现下面的链接,但没有一个对我有效。其中一些不是特定于Serenity-BDD的。
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
}
}我的Maven版本是:


发布于 2020-12-10 06:57:23
在测试执行之前,我不确定我是否理解了您的目的以及您想要做什么。由于您使用的是Serenity框架,因此我建议您考虑一下StepListener实现。它使用Java SPI。它可能会对你的任务有所帮助。
简而言之:
Serenity具有类StepEventBus,该类具有在测试执行之前从类路径加载服务实现的逻辑。您只需要实现自定义的StepListener和覆盖方法。在此之后,您将能够在不同的运行阶段(功能启动、测试启动、步骤启动等)上运行您的代码。
https://stackoverflow.com/questions/61815030
复制相似问题