Trouble taking Screenshot of failed tests

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble taking Screenshot of failed tests

Pritz
Hi,
I was executing the code in 6th Selenium Training Session. I am facing problem w.r.t. taking screenshots of failed test cases. Although the tests fail, which can be seen in the TestNG Report, the screenshots are missing under test-output folder. The code for the same of @AfterMethod of SelTestCase.java is below.. Pls help

        @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.moveFile(imageFile, failureImageFile);
                       
                }
               
                driver.close();
                driver.quit();
        }
Reply | Threaded
Open this post in threaded view
|

Trouble taking Screenshot of failed tests

Pritz
Hi,

After much do's and dont's, when by chance I checked the project folder location manually, I found that the screenshots were actually being created but getting stored outside test-output directory!!!! Half problem solved, but why are the screenshot png files misplaced? How do I rectify this? Thanks in advance..