`尝试在黄瓜框架中创建一个钩子,出现以下错误,不确定我缺少什么 抑制:io.cucumber.java.InvalidMethodSignatureException:用 Before、After、Before Step 或 After Step 注释的方法必须具有以下签名之一:
@BeforeStep
public void beforeStep() {
System.out.println(" @BeforeStep");
}
@AfterStep
public void AfterStep(ITestResult scenario) throws IOException {
if (ITestResult.FAILURE == scenario.getStatus()) {
File screenshot =((TakesScreenshot)
driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot,new File("C:\\Users\\Admin\\eclipse-workspace\\Cucumber_screenshot_Failure\\test-output\\screenshots\\Failure.png"));
}
来自此处的文档: https://cucumber.io/docs/cucumber/api/?lang=java#hooks
beforeStep 方法的正确代码如下所示:
@BeforeStep
public void beforeStep(Scenario scenario){
}
InvalidMethodSignatureException
告诉您方法签名不正确,这意味着返回类型、参数或方法范围对于注释无效。
如果您添加
Scenario scenario
参数,它应该可以解决您的问题。