Skip to main content

ExtentReports in Selenium Webdriver

ExtentReports in Selenium Webdriver




What is ExtentReport?

ExtentReports  is a HTML reporting library for Selenium WebDriver for Java which is extremely easy to use and creates beautiful execution reports. It shows test and step summary, test steps and status in a toggle view for quick analysis

Download

Download the jar below:

Snapshot of Extent report After Executing the Script

 

Program Steps: 

We are going to write three different testcases.

  • Pass
  • Warning
  • Fail

TestCase with Pass Result
  1. Navigate to http://www.guvi.in
  2. Click on Sign-in
  3. Enter the credientials
  4. Check the URL is correct or not after login
 TestCase with Warning Result

  • Verify with the Wrong URL (static String Afterloginfail="http://www.guvi.in/")
  TestCase with fail Result

  • Click on Menu
  • Select Tech Challenges
  • Verify With wrong URL.

Source Code:





import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;

import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.GridType;
import com.relevantcodes.extentreports.LogStatus;
import com.sun.jna.platform.FileUtils;



public class ReportDemo {
       static final ExtentReports extent=ExtentReports.get(ReportDemo.class);
       static WebDriver driver=new FirefoxDriver();
       static String AfterLogin="http://www.guvi.in/PublicPlaylists";
       static String reportLocation = "C:\\Tools\\reports\\";
       static String Afterloginfail="http://www.guvi.in/" ;
       static String imageLocation = "images/";
       static String jobs="http://www.guvi.in/jobs";
       static String jobsfail="http://www.guvi.in/job";

       public static void main(String[] args) throws InterruptedException {
              // TODO Auto-generated method stub
              extent.init(reportLocation+"ScreenshotReport.html",true,DisplayOrder.BY_OLDEST_TO_LATEST,GridType.STANDARD);
              extent.config().displayTestHeaders(true);
              extent.config().documentTitle("Guvi test Reports");
              extent.config().reportHeadline("Automation Test Report for Guvi");
             
              //Start of TC1 with pass result
              extent.startTest("This Test to check the login crediential with Correct");
              extent.config().displayCallerClass(false);
              runWithCorrectCredientails();
              extent.attachScreenshot(createScreenshot(driver),"This is to attach screenshot for test");
              extent.log(LogStatus.PASS"Link""Check the Link After Login: <a href='http://www.guvi.in/PublicPlaylists'>link</a>.");
              extent.config().useExtentFooter(false);
         
              extent.endTest();

             
              //Fail
              extent.startTest("This Test to check is to verify the redirection link");
              extent.config().displayCallerClass(false);
             
              if(driver.getTitle().equals(Afterloginfail)) {
            extent.log(LogStatus.PASS"Check page title""Page title is " +AfterLogin);
        } else {
            extent.log(LogStatus.WARNING"Check page title""Incorrect login page title " + Afterloginfail);
        }
              extent.endTest();
             
              extent.startTest("This is used to check jobportal url ");
              extent.config().displayCallerClass(false);
              Thread.sleep(10000);
             driver.findElement(By.xpath("html/body/header/div[2]/div/div[1]/ul/li/button")).click();
              driver.findElement(By.cssSelector("a.li-boot")).click();
              if(driver.getTitle().equals(Afterloginfail)) {
            extent.log(LogStatus.PASS"Click on job portal""Page title is "jobs);
        } else {
            extent.log(LogStatus.FAIL"Check job portal url""Incorrect login page title " + jobsfail);
        }
             
             
              extent.endTest();
             
              driver.quit();

       }
      
       public static void runWithCorrectCredientails() throwsInterruptedException
       {
              driver.get("http://www.guvi.in/");
              driver.manage().window().maximize();
             driver.findElement(By.xpath("html/body/header/div[2]/div/div[3]/ul/li[1]/a")).click();
              Thread.sleep(5000);
             driver.findElement(By.id("login_email")).sendKeys("kk.prashanth65@gmail.com");
              Thread.sleep(5000);
              driver.findElement(By.id("login_password")).sendKeys("test123");
              Thread.sleep(5000);
              driver.findElement(By.id("login_button")).click();
              Thread.sleep(5000);
              String expgeturl=driver.getCurrentUrl();
              driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
              Thread.sleep(8000);
              if(driver.getCurrentUrl().equals(AfterLogin))
              {
                   extent.log(LogStatus.PASS"Check page title""Page title is " + expgeturl);
           }
              else {
                   extent.log(LogStatus.FAIL"Check page title""Incorrect login page title " + driver.getTitle());
               }    
       }
      
       public static String createScreenshot(WebDriver driver) {
               
           UUID uuid = UUID.randomUUID();
          
        
           // generate screenshot as a file object
           File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
           try {
               // copy file object to designated location
              org.apache.commons.io.FileUtils.copyFile(scrFile, newFile(reportLocation + imageLocation + uuid + ".png"));
              System.out.println(imageLocation + uuid + ".png");
           } catch (IOException e) {
               System.out.println("Error while generating screenshot:\n" + e.toString());
           }
           return reportLocation + imageLocation + uuid + ".png";
          
       }


}


  

 Run the program

TestCase with Pass Result



TestCase with Warning Result  and TestCase with fail Result

Full report

 Thats it..

Thank you.. 

Comments

Popular posts from this blog

Reporting in Selenium

How do you Handle reporting in your project ? Method 1 : Maven - Testng - Surefire report The project will be created in Maven with  SureFire Plugin  and  SuiteXmlFile  tag in the POM.xml . The testng.xml will be called in the POM.            <plugin>                 <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-surefire-plugin</artifactId>            <version>2.18.1</version>                 <configuration>                     <suiteXmlFiles>                         <suiteXmlFile>                             ...

Handling Modal Dialog Window in Selenium Webdriver

Handling Modal Dialog Window in Selenium Webdriver In this tutorial we are going to see how to handle " Modal Dialog Window "  using Selenium Webdriver Disadvantage using Selenium Use Can't handle elements which is inside  Modal Dialog Window. Using Robot Class Using Robot Class we can handle  Modal Dialog Window. In this tutorial Open  http://vodkabears.github.io/remodal/# Click on  Show  button In the  Modal Dialog Window.  Click on Follow button  Source Code : import java.awt.AWTException; import java.awt.Robot; import java.awt.Toolkit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; public class robot_demo { public static void main(String[] args) throws InterruptedException, AWTException { WebDrive...

Autonium

About Autonium Autonium is a test automation framework for web applications. This framework is built by using Java and Selenium. It uses Maven project structure. Easy to understand and use it. Having basic idea on Java, Selenium, Maven and TestNG is good enough to start with Autonium. Let’s start Automation with Autonium --------------------------------------------------- Advantages Provides support to all major browsers –  Firefox, Chrome, IE and Safari . Capability of executing scripts on  Remote Machines  by using Selenium Server. Users can make use of Selenium Web driver methods and Autonium methods. Autonium simplifies  Test data management . Test data can be read from properties files. Scripts can be developed without  hard coding  test data . Identifiers can also be read from properties files and  hard coding   of identifiers can be avoided. Test data and Identifier v...