我已經聲明了 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)”。此錯誤消息來自第二種方法。
@After 和@Before 注釋沒有執行第二種方法
慕碼人8056858
2023-04-26 16:23:22