亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

@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 關注
  • 238 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號