我使用@BeforeTest注释和Cucumber hoo使用@Before注释实现了TestNG钩子,但是在运行代码时显示错误。
错误:
[Utils] [ERROR] [Error] java.lang.NullPointerException 在Runner.TestRunner.features(TestRunner.java:105)
FAILED CONFIGURATION:@BeforeTest setUp java.lang.NoClassDefFoundError: io / cucumber / tagexpressions / TagExpressionParser at cucumber.runtime.TagPredicate。(TagPredicate.java:23)
引起:java.lang.ClassNotFoundException: io.cucumber.tagexpressions.TagExpressionParser
FAILED CONFIGURATION:@AfterTest tearDown java.lang.NullPointerException at Runner.TestRunner.tearDown(TestRunner.java:110)
Login.java
public class Login {
private PropertiesManager pm;
private ExtentReportManager reportMgr;
public Login() {
}
/*@Before("@p")
public void setUp() {
pm = PropertiesManager.createInstance();
reportMgr = ExtentReportManager.createInstance();
}*/
}
TestRunner.java
@CucumberOptions(
features = "src/Feature",
glue = {"Step_Definitions"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json",
"rerun:target/cucumber-reports/rerun.txt"
})
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;
private ExtentReportManager reportMgr;
private PropertiesManager pm;
@BeforeTest(alwaysRun = true)
public void setUp() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
pm = PropertiesManager.createInstance();
reportMgr = ExtentReportManager.createInstance();
WebDriverManager.createDriver();
}
@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "dataProvider")
public void feature(CucumberFeatureWrapper cucumberFeature) {
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}
}
为什么Cucumber hook和TestNG hook之间存在冲突?怎么解决?谢谢。
答案 0 :(得分:0)
我通过在构建路径中添加tag-expression.jar来解决它。