Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
February 25, 2017

Capture FullPage Screenshot in Extent Reports – Java





Capture Screenshot in Extent Reports will discuss about capturing the screenshot of a particular failure step in the HTML report.  In our previous blog we have seen how to log the messages in the report. Same way here we will capture the screenshot for a particular failure step. The screenshot will give the information about on which screen the script  got failed during the execution. Then we can easily identify the issue by looking into the report.

But the issue from Selenium 3 is; it will not capture the full screenshot of the particular page rather it will capture only the visible area of the web page. But sometimes we need to capture full page of the particular web page. Then we can not use the normal screenshot functionality which is provided by the selenium. For this we will use Ashot to capture the full page screenshot of the particular web page. In one of our previous blogs we have seen how to capture the same using Ashot. In this blog, we will use Ashot functionality and make that available in the extent reports.

For this we need to use the log() method of ExtentTest class. To log the screenshot in the report we need to pass the path of the screenshot to the log method as a parameter. So, before logging the screenshot to the report we need to capture the full page screenshot of that particular failure and place it in a folder, from there we need to get the path of the screenshot file and pass it to the log method.

Below is the sample program to capture screenshot in the report:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

public class CapturingFullPageScreenshot
{
    ExtentHtmlReporter htmlReporter;
    ExtentReports extent;
    ExtentTest test;
    WebDriver driver;
    
    @BeforeTest
    public void config()
    {
        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
    }
    
    @Test
    public void captureScreenshot()
    {
        test = extent.createTest("captureScreenshot");
        System.setProperty("webdriver.gecko.driver", "/KRISHNA VOLUME/drivers/geckodriver");
        driver = new FirefoxDriver();
        driver.get("https://automationtesting.in");
        String title = driver.getTitle();
        Assert.assertEquals("Home - Automation Test", title);
    }
    
    @AfterMethod
    public void getResult(ITestResult result) throws Exception
    {
        if (result.getStatus() == ITestResult.FAILURE)
        {
            String screenShotPath = GetFullPageScreenShot.capture(driver, "MyFullPageScreenshot");
            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:", ExtentColor.RED));
            test.fail(result.getThrowable());
            test.fail("Snapshot below: " + test.addScreenCaptureFromPath(screenShotPath));
        }
        else if(result.getStatus() == ITestResult.SUCCESS)
        {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
        }
        else
        {
            test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
            test.skip(result.getThrowable());
        }
        extent.flush();
    }
    
    @AfterTest
    public void endReport()
    {
        driver.quit();
    }
}

In the above program we have written  test.log method to log the screenshot into the extent reports. This information will logged in the report with time stamp.



In the above program we have written  test.log method to log the screenshot into the extent reports. This information will logged in the report with time stamp. addScreenCaptureFromPath() is a method to place the screenshot in the extent report.

Below is the program to capture the full page screenshot and it will place the screenshot in a particular folder and will return the path of the screenshot. Will use that path to capture the full page screenshot in the HTML report for a failure step.

import org.openqa.selenium.WebDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

import javax.imageio.ImageIO;
import java.io.File;

public class GetFullPageScreenShot
{
    public static String capture(WebDriver driver, String screenShotName) throws Exception
    {
        Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
        String dest = System.getProperty("user.dir") + "/ErrorScreenshots/" + screenShotName + ".png";
        ImageIO.write(screenshot.getImage(),"PNG",new File(dest));
        return dest;
    }
}

Above program will return the path of the screenshot.

Below is the output of the above program:

FullPage Screenshot in the Report

 

Please watch the YouTube video of this blog for better understanding.



Share this post: on Twitter on Facebook

Capture Screenshot in Extent Reports – Java – Version3 Extent Report With Multiple Classes

Related Posts

GENERATE EXTENT REPORT WITH MULTIPLE CLASSES JAVA

Extent Reports-Java-Version3

Extent Report With Multiple Classes

CAPTURE SCREENSHOTS IN EXTENT REPORTS JAVA

Extent Reports-Java-Version3

Capture Screenshot in Extent Reports – Java – Version3

EXTENT REPORTS LOG GENERATION JAVA

Extent Reports-Java-Version3

Extent Reports Log Generation – Java – Version3

GENERATING EXTENT REPORTS JAVA-V3

Extent Reports-Java-Version3

Generating Extent Reports – Java – Version3

EXTENT REPORTS INTRODUCTION JAVA

Extent Reports-Java-Version3

Extent Reports Introduction – Java – Version3

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025