问题描述
我试图在 serenity-bdd
项目中实现全局挂钩.当我浏览下面的链接时,没有一个对我有用.不过其中一些并非特定于Serenity-BDD.
package mypackage;导入org.junit.runner.RunWith;导入cumul.api.CucumberOptions;导入net.serenitybdd.cucumber.CucumberWithSerenity;@RunWith(CucumberWithSerenity.class)@CucumberOptions(features ="src/test/resources/features",胶= {"MyProj.cucumber.stepdefinition"},公共课程MyTest {@前公共静态无效setUp(){//在这里做点事}}
在执行测试之前,我不确定是否抓住了您的目的以及您想做什么.由于您使用Serenity框架,因此建议您查看StepListener的实现.它使用 Java SPI .可能对您的任务很有用.
简而言之:
Serenity具有类StepEventBus,该类具有在测试执行之前从类路径加载服务实现的逻辑.您只需要实现自定义StepListener和重写方法.然后,您将能够在不同的运行阶段(功能启动,测试启动,步骤启动等)运行代码的安全性
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
}
}
My Maven versions are:
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.)
这篇关于Serenity BDD中的全局钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!