Selenium 2 WebDriver Advanced
  • Preface
  • 1. API Testing Using Selenium WebDriver
    • 1.1 Code Snippet for API testing
    • 1.2 SoapUI
      • 1.2.1 Add selenium jars to soapUI
      • 1.2.2 Run selenium tests
      • 1.2.3 Data Driven Testing using SoapUI
  • 2. Advanced Profiles for Browsers
    • 2.1 Profile for Firefox Browser
    • 2.2 Profile for Chrome Browser
    • 2.3 Profile for IE Browser
    • 2.4 Profile for Safari Browser
    • 2.5 Profile for Opera Browser
  • 3. TestNG
    • 3.1 Sample TestNG class
    • 3.2 Parallel execution
    • 3.3 Execution of tests from batch file
  • 4. ExtentReports
    • 4.1 Basics
    • 4.2 Sample Extent Reports
  • 5. Advanced tricks
    • 5.1 Keystroke handling
    • 5.2 Screenshot capture
    • 5.3 Get HTML Source of WebElement
Powered by GitBook
On this page

Was this helpful?

  1. 4. ExtentReports

4.2 Sample Extent Reports

Extent Reports is a multi-format reporting library for Java Developers which creates an interactive HTML report, an email report, and also provides real-time log information. The ExtentAPI also integrates with the ExtentX server to provide in-depth views of your tests.Extent addresses the reporting issues in TestNG.

Below is the code which can be used to run tests

package code;

import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.NetworkMode;

import CONSTANTS;

public class ExtentManager {
    public static ExtentReports extent;
    protected static final String filePath=System.getProperty("user.dir")+File.separator
    +"ExtentReports"+File.separator+"TestReport.html";
    private static boolean replaceExisting=true;
    protected static final DisplayOrder displayOrder= DisplayOrder.NEWEST_FIRST;

    public static ExtentReports getInstance(String EnvironmentToRunOn) {
        if (extent == null) {
            extent = new ExtentReports(filePath, replaceExisting,displayOrder, NetworkMode.OFFLINE); 
            extent.loadConfig(new File(CONSTANTS.ExtentConfigPath));
            Map<String, String> sysInfo = new HashMap<String, String>();
            sysInfo.put("Selenium Version", "2.53.1");
            sysInfo.put("Environment", EnvironmentToRunOn);
            extent.addSystemInfo(sysInfo);            
        }
        return extent;
    }
}

class ExtentReports {

    public ExtentReports extent;
    public ExtentTest test;
    public String getCurrentlyLoggedInUser=System.getProperty("user.name");

    @Test       
   public void InitializeExtentReport(){
        //Instantiating the ExtentReports
        extent=ExtentManager.getInstance(Environment);
        extent.assignProject("Test Extent");
        // start x requires MongoDB hence commented to generate reports on the other machines
        Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
        mongoLogger.setLevel(Level.SEVERE);
        extent.x("localhost");*/
        test=extent.startTest("Test1", ""Application started." );
        test.assignAuthor(getCurrentlyLoggedInUser);
        test.assignCategory("RegressionTestCases");
        }
    }

We need to keep in mind that the extent reports must be under @Test annotation of TestNG otherwise it will not generate the reports.

After running the tests we will be able to view report in the specified folder as "TestReport.html"

Previous4.1 BasicsNext5. Advanced tricks

Last updated 5 years ago

Was this helpful?