簡體   English   中英

@After 和 @Before 注釋不執行第二種方法

[英]@After and @Before annotation is not executing second method

我已經聲明了 2 個方法 @after 注釋,但它只會執行第一個方法,它不允許我執行第二個方法。 請看下面的代碼

我想每次退出瀏覽器都執行 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);
        }
    }
}

從未使用方法“屏幕截圖(cucumber.api.Scenario)”。 此錯誤消息來自第二種方法。

您只標記了browserTearDown()方法。

@After標記添加到Screenshot()方法中,以及:

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

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM