为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕码人8056858 2023-04-26 16:23:22
我已经声明了 2 个方法 @after 注解,但它只会执行第一个方法,它不允许我执行第二个方法。请看下面的代码我想每次退出浏览器都执行1个方法。我想对失败的测试用例执行第二种方法。@Beforepublic 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());}@Afterpublic 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);        }    }}从未使用过方法“屏幕截图(cucumber.api.Scenario)”。此错误消息来自第二种方法。
查看完整描述

1 回答

?
HUX布斯

TA贡献1876条经验 获得超6个赞

你只标记了browserTearDown()方法。


也将@After标记添加到方法中:Screenshot()


@After

public void browserTearDown()

{

    System.out.println("End the browser");

    driver.close();

}


@After

public void Screenshot(Scenario scenario) {

   ...


}


查看完整回答
反对 回复 2023-04-26
  • 1 回答
  • 0 关注
  • 98 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信