繁体   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