Back

Explore Courses Blog Tutorials Interview Questions
0 votes
10 views
in Java by (120 points)

Unable to capture screenshot using extent report version 4(selenium-java).

Error msg:-FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=expediaTitleCheck status=FAILURE method=Expedia_TC.expediaTitleCheck()[pri:0, instance:[email protected]] output={null}])

Code is as follows:-

public class Expedia_TC {
    WebDriver driver;
    Expedia exp;
    ExtentHtmlReporter htmlReport;
    ExtentReports extent;
    ExtentTest test;
   
    @BeforeTest
    public void startBrowser() {
        htmlReport = new ExtentHtmlReporter(System.getProperty("user.dir")+"/Reports/ExpediaReport.html");
        htmlReport.config().setEncoding("utf-8");
        htmlReport.config().setDocumentTitle("Expedia Automation Report");
        htmlReport.config().setReportName("Functional Report");
        htmlReport.config().setTimeStampFormat("EEEE,DD-MM-YYYY,hh:mm:ss");
        htmlReport.config().setTheme(Theme.DARK);
        extent = new ExtentReports();
        extent.attachReporter(htmlReport);
        extent.setSystemInfo("OS","Windows10");
        extent.setSystemInfo("Environment","Production");
        extent.setSystemInfo("Tester","Jayashree");
       
        WebDriverManager.firefoxdriver().setup();
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
        driver = new FirefoxDriver();
        exp = new Expedia(driver);
        driver.manage().window().maximize();
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
    }
   
    @Test
    public void expediaTitleCheck() {
        test = extent.createTest("Title Check Test...");
        exp.checkPageTitle();
        test.fail("This Test is Failed!");
   
    }
    @AfterMethod
    public void tearDown(ITestResult result)throws IOException {
        if(result.getStatus() == ITestResult.FAILURE) {
            String methodName ="<b>"+result.getMethod().getMethodName()+" : "+"FAILED"+"</b>";
            String errorMsg = "<b>"+"REASON: "+" "+result.getThrowable().getMessage()+"</b>";
            String failureScreenshot = Expedia_TC.captureScreen(driver, methodName);
            test.log(Status.FAIL,MarkupHelper.createLabel(methodName,ExtentColor.RED));
            test.log(Status.FAIL,errorMsg);
            try {
            test.addScreenCaptureFromPath(failureScreenshot);
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
}
   

    @AfterTest
    public void endReport() {
        extent.flush();
        driver.quit();
    }
   
   
     public static String captureScreen(WebDriver driver,String screenshotname)throws IOException {
        String date = new SimpleDateFormat("MM-dd-yy,hh:mm:ss").format(new Date());
        TakesScreenshot ts = (TakesScreenshot)driver;
        File src= ts.getScreenshotAs(OutputType.FILE);
        String path = System.getProperty(("user.dir")+"/ScreenShots/"+screenshotname+date+".png");
        File destination = new File(path);
        FileUtils.copyFile(src, destination);
        return path;
       
}

}
 

Please log in or register to answer this question.

Browse Categories

...