簡體   English   中英

截圖未在TestNG,Selenium中的test-output文件夾下創建

[英]Screenshots not created under test-output folder in TestNG, Selenium

我是Selenium WebDriver的新手。 我正在使用以下方法拍攝Selenium,TestNG中失敗的測試的屏幕截圖。 執行后,testNG報告完美地顯示了失敗的測試,並且成功創建了imageFile輸出文件,但是在test-output文件夾下沒有屏幕截圖。 手動檢查時,我發現屏幕截圖是在項目文件夾中的test-output文件夾之外創建的。 我該如何糾正,以便屏幕截圖顯示在test-output文件夾下?

@AfterMethod 
public void closeBrowser(ITestResult result) throws IOException {
    if (!result.isSuccess()){
        File imageFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        String failureImageFileName = result.getMethod().getMethodName()+new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime()) + ".png";
        File failureImageFile = new File(failureImageFileName);
        FileUtils.copyFile(imageFile, failureImageFile);

    }
public void closeBrowser(ITestResult result) throws IOException {
    if (!result.isSuccess()){
        File imageFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        String failureImageFileName = result.getMethod().getMethodName()+new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime()) + ".png";

        // It will store all the screenshots in test-output/screenshots folder
        String destDir = System.getProperty("user.dir")) + "/" + "test-output/screenshots";
        new File(destDir ).mkdirs();
        String destFile = destDir + "/" + failureImageFileName;
        FileUtils.copyFile(imageFile, new File(destFile ));
    }

暫無
暫無

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

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