首页 > 解决方案 > @AfterStep/@BeforeStep 不适用于 Cucumber Selenium Java

问题描述

我在黄瓜硒java项目中苦苦挣扎@AfterStep/@Beforestep。

当我使用 @AfterStep 黄瓜钩子时,它不执行该方法(它跳过该方法)

我尝试了很多版本,但仍然没有运气。

谁能帮我处理没有兼容性问题的最新版本的 POM 文件

我把这个文件放在 stepDefinition 并使用 cucumber.api.java.AfterStep

    @AfterStep
public void tearDown(Scenario scenario) throws IOException, JiraException 
{
   System.out.println("in step method");
   if (scenario.isFailed()) {
   System.out.println("in failes screen");
   File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
   String path=null;
   path=System.getProperty("user.dir")+"\\target\\Screenshot\\"+System.currentTimeMillis()+".png";
   FileUtils.copyFile(scrFile, new File(path));
   Reporter.addScreenCaptureFromPath(path);
   Reporter.addStepLog(scenario.getId());
  }
}

测试运行者:

    @RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/extentPackage/LoginToABSi.feature"},
glue = {"stepDefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/report.html"}
)
public class RunCukesTest {

     public static WebDriver driver;
     public static WebDriverWait wait;
     public static ExtentProperties extentProperties;

@AfterClass
public static void teardown() {

Reporter.loadXMLConfig(new File("Report-Config/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Reporter.setTestRunnerOutput("Sample test runner output message");

}

标签: selenium-webdrivercucumber

解决方案


推荐阅读