SELENIUM BASICS:

  • What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation

  • SELENIUM WEBDRIVER:

  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver

  • TESTNG:

  • TestNG Installation
  • TestNG Complete Tutorial

  • REPORTS:

  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4

  • BUILD & CONTINUOUS INTEGRATION TOOLS:

  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide

  • CROSS BROWSER TESTING:

  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices

  • MOBILE TESTING:

  • Mobile Testing Platform with Real Devices

  • AUTOMATION FRAMEWORKS:

  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)

  • INTERVIEW QUESTIONS:

  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions

  • SAMPLE RESUME:

  • Automation Tester Resume
  • Extent Reports – Screenshots of Failed Test Cases in Extent Reports

    Insert Screenshots of a Failed Test Cases in Extent Reports:

    In this post, we see how to add Screenshots in Extent Reports – Selenium WebDriver.

    Check this post for Latest Version of Extent Reports.

    Pre-requisites to Insert Screenshots in Extent Reports:

    1. Java should be installed (Link to Install and setup Java )
    2. TestNG should be installed
    3. Extent Report Jars (Version 2.41.2) – Download
    4. extent-config.xml – It allows to configure HTML Report

    Steps To Generate Extent Reports:

    1. Firstly, create a TestNG project in eclipse
    2. Now download extent library files from the following link: http://extentreports.com/
    3. Add the downloaded library files in your project
    4. Add Selenium WebDriver Jars
    5. Create a java class say ‘ExtentReportsClass’ and add following code to it

    NOTE: In this post, I am not explaining everything. In the earlier post (i.e., Generate ExtentReports), I have mentioned detailed explanation. In this I just explain how to capture screenshot and pass it to the extent reports.

    Below mentioned method is to capture the screenshot and returns the path of the screenshot.

    Same code (getScreenshot method) I have placed in the below TestNG Class. You could also place this code in your utilities function class.

    If you are a beginner and wants to know how to capture screenshot then check this post on how to capture screenshot in Selenium and this post to capture full page screenshot using aShot

    Program to insert captured screenshots in extent reports:

    extent-config.xml: 

    By using this external XML file (extent-config.xml), we could change the details such as Report Theme (either standard or dark), Report Title, Document Title etc.,

    We use extent object and use loadConfig() method to load this xml file.

    Refresh the project after execution of above ExtentReportsClass.java file. You could find an HTML file named “STMExtentReport.html” in your test-output folder. Copy the location of the STMExtentReport.html file and open it by using any browser. You could see a beautiful high rich HTML reports as shown below.

    Extent Report – Test Summary Report Which Contains Screenshot of a Failed Test Case:

    Screenshot Failed Test Case Extent Reports

     

    This way we could add screenshots of a failed test cases in extent reports.

    You could also find introduction of extentreports by clicking on this link

    Extent Reports With Screenshots

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.

    Rajkumar

    4 thoughts on “Extent Reports – Screenshots of Failed Test Cases in Extent Reports”

    1. Thanks for the superb post on capture screenshot in extent reports.

    2. Hi,
      I added the same code but Image is not attached to the report. Image displayed as a line.
      By Looking in to my Code can you please help me where is the error.

      I am using Latest version Extentreports-3.1.1.jar

      public static WebDriver driver;
      public static WebDriverWait wait;
      public static Properties sprops = new Properties();
      public static Properties aprops = new Properties();
      public String ScrPath = System.getProperty(“user.dir”);
      public File SharedRepofile = new File(ScrPath+”\\Repositories\\SharedRepo.properties”);
      public FileInputStream SharedRepoInputFile;
      public FileInputStream AppRepoInputFile;
      public String ErrScPath = System.getProperty(“user.dir”)+”\\ErrorScreenshots\\”;

      public String CaptureScreenShot(String screenshotname) throws Exception{
      DateFormat DF = new SimpleDateFormat(“dd-MM-yyyy_HHmmss”);
      Date D = new Date();
      String time = DF.format(D);
      TakesScreenshot ts = (TakesScreenshot)driver;
      File Source = ts.getScreenshotAs(OutputType.FILE);
      String dest = ErrScPath + screenshotname+”_”+time+”.png”;
      File destination = new File(dest);
      FileUtils.copyFile(Source, destination);
      return dest;
      }

      @BeforeTest()
      public void beforeTest(String Browser, String DataFile, String AppRepofile ) throws Exception {
      if (Browser.equalsIgnoreCase(“Chrome”)) {
      ChromeOptions options = new ChromeOptions();
      options.addArguments(“test-type”);
      options.addArguments(“disable-popup-blocking”);
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      System.setProperty(“webdriver.chrome.driver”, “D:\\lib\\chromedriver.exe”);
      driver = new ChromeDriver();
      }
      else if(Browser.equalsIgnoreCase(“IE”)){
      System.setProperty(“webdriver.ie.driver”, “D:\\lib\\IEDriverServer.exe”);
      driver = new InternetExplorerDriver();
      }
      else if(Browser.equalsIgnoreCase(“Firefox”)) {
      System.setProperty(“webdriver.gecko.driver”, “D:\\lib\\geckodriver.exe”);
      driver = new FirefoxDriver();
      }

      Capabilities cap = ((RemoteWebDriver)driver).getCapabilities();
      String OS = System.getProperty(“os.name”);
      String BrowserName = cap.getBrowserName().toLowerCase();
      String Version = cap.getVersion();

      HtmlReporter = new ExtentHtmlReporter(System.getProperty(“user.dir”)+”\\CustomReport\\MyOwnReport.html”);
      Extent = new ExtentReports();
      Extent.attachReporter(HtmlReporter);

      Extent.setSystemInfo(“OS”, OS);
      try {
      Extent.setSystemInfo(“Host Name”, Inet4Address.getLocalHost().toString());
      } catch (UnknownHostException e) {
      e.printStackTrace();
      }
      Extent.setSystemInfo(“Web Browser”, BrowserName);
      Extent.setSystemInfo(“Browser Version : “, Version);

      HtmlReporter.config().setChartVisibilityOnOpen(true);
      HtmlReporter.config().setDocumentTitle(“Logix Health Automation Test Report”);
      HtmlReporter.config().setReportName(“Logix Express”);
      HtmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
      HtmlReporter.config().setTheme(Theme.STANDARD);

      setExcelFile(ScrPath+DataFile);

      driver.get(GetDatafromCell(“Global”, 2, “URL”));
      driver.manage().window().setSize(new Dimension(1280, 1024));
      Thread.sleep(3000);

      SharedRepoInputFile = new FileInputStream(SharedRepofile);
      sprops.load(SharedRepoInputFile);
      AppRepoInputFile = new FileInputStream(ScrPath+AppRepofile);
      aprops.load(SharedRepoInputFile);

      login(GetDatafromCell(“Global”, 2, “UID”), GetDatafromCell(“Global”, 2, “PWD”));

      Thread.sleep(5000);
      }

      @AfterSuite
      public void afterSuite() {
      File f = new File(System.getProperty(“user.dir”)+”\\CustomReport\\MyOwnReport.html”);
      if (f.exists()) {
      String oldtDir = System.getProperty(“user.dir”) + “\\CustomReport\\Old\\”;
      File fold = new File(oldtDir);
      //f= new File(“MyOwnReport.html”).renameTo(new SimpleDateFormat(“dd-MM-yyyy HH:mm:ss”).format(new Date()+”MyOwnReport.html”);
      String rn = new SimpleDateFormat(“dd-MM-yyyy HH:mm:ss”)+”MyOwnReport.html”;
      File nf = new File(rn);
      f.renameTo(nf);
      try {
      FileUtils.moveFileToDirectory(f, fold, true);
      } catch (IOException e) {
      e.printStackTrace();
      }
      }

      Extent.flush();
      }

      @BeforeMethod
      public void beforeMethod(Method method) {
      Test = Extent.createTest((this.getClass().getSimpleName()));
      }

      @Test
      public void forTest() throws Exception {
      driver.findElement(By.linkText(“Dashboard”)).click();
      Thread.sleep(6000);
      }

      @Test
      public void forTest2() throws Exception {
      driver.findElement(By.linkText(“Work Queue”)).click();
      driver.findElement(By.id(“toggleOutstanding”)).click();
      Thread.sleep(3000);
      }
      @AfterMethod
      public void getResult(ITestResult result) throws Exception{
      if (result.getStatus() == ITestResult.FAILURE) {
      // With Java Screen Capture
      String imagepath = CaptureScreenShot(result.getName());
      Test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + ” Test case FAILED due to below issues:”, ExtentColor.RED));
      //Test.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable()+ ” Test case FAILED :”, ExtentColor.RED));
      //Test.fail(result.getThrowable());
      //Test.log(Status.FAIL, (Markup) Test.addScreenCaptureFromPath(imagepath));
      //Test.log(Status.FAIL, Test.addScreenCaptureFromPath(imagepath));
      Test.fail(“Snapshot below : ” + Test.addScreenCaptureFromPath(imagepath));
      }
      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());
      }

      }

      • Hi Ramesh, try this OutputType.BASE64 instead of OutputType.FILE

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap