简体   繁体   English

截图未在TestNG,Selenium中的test-output文件夹下创建

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

I am new to Selenium WebDriver. 我是Selenium WebDriver的新手。 I am using the following method to take screenshots of failed tests in Selenium, TestNG. 我正在使用以下方法拍摄Selenium,TestNG中失败的测试的屏幕截图。 After execution, the testNG report shows the failed tests perfectly and also the imageFile outputfile is successfully created, but no screenshots appear under test-output folder. 执行后,testNG报告完美地显示了失败的测试,并且成功创建了imageFile输出文件,但是在test-output文件夹下没有屏幕截图。 When I manually checked, I found that the screenshots were being created outside the test-output folder, in the project folder. 手动检查时,我发现屏幕截图是在项目文件夹中的test-output文件夹之外创建的。 How do I rectify this, so that the screenshots appear under test-output folder? 我该如何纠正,以便屏幕截图显示在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