@After 和@Before 注释没有执行第二种方法

@After and @Before annotation is not executing second method

我在@after注解中声明了2个方法,但它只会执行第一个方法,不允许我执行第二个方法。请看下面的代码

我想每次退出浏览器执行1个方法。 我想对失败的测试用例执行第二种方法。

@Before
public void databaseLoading(Scenario scenario) {
    //System.out.println("Test Environment Set Up");
    System.out.println("\n------------------------------------------------     TEST ENVIRONMENT SET UP      ------------------------------------------------------------------------------\n");
    System.out.println("Executing Scenario :-> " + scenario.getName());
}

@After
public void browserTearDown()
{
    System.out.println("End the browser");
    driver.close();
 }

public void Screenshot(Scenario scenario) {
    // take the screenshot at the end of every test
    String location = ".\target\TakeScreenshot";
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy hh-mm-ss", Locale.ENGLISH);
    Date date = new Date();
    File scrFile =
            ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    // now save the screenshto to a file some place
    if (scenario.isFailed()) {
        try {
            FileUtils.copyFile(scrFile, new File(location + "\" + dateFormat.format(date) + ".png"));
            System.out.println("Screenshot saved");
        } catch (IOException e) {
            System.out.println("Error in taking Screenshot --> " + e);
        }
    }
}

从未使用过方法'Screenshot(cucumber.api.Scenario)'。此错误消息来自第二种方法。

您只标记了 browserTearDown() 方法。

@After 标记添加到 Screenshot() 方法,以及:

@After
public void browserTearDown()
{
    System.out.println("End the browser");
    driver.close();
}

@After
public void Screenshot(Scenario scenario) {
   ...

}