Thursday 16 February 2017

SELENIUM : Extent Reports 2.X



Extent Reports 2.X:
--------------------------
Steps to Work with Extent Reports 2.X:

1. Download  Extent Reports jar file(s),and add to the Project.
open google------>type 'Download Extent Reports'------------>Click on 'ExtentReports for awesome selenium webdriver reporting-------->click on ExtentReports-java-v2 40.2---------->OK

2. Get the ExtentReports(C) object,and give the path of the location where you want to store reports)
Ex: ExtentReports ext=new ExtentReports("C:\\Users\\ramesh\\Desktop\\DemoReports\\report1.html");

3.Get the ExtentTest(C) object
Ex:
ExtentTest logger=ext.startTest("Gmail Test");

4.Log the reports
Ex: logger.log(LogStatus.INFO, "URL is passed");

5.End the Test and call flush().

Ex: ext.endTest(logger);
       ext.flush();
         
Example:

package com.rameshsoft;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class Demo1 {
         
          public static void main(String[] args) throws InterruptedException {                  
                   ExtentReports ext=new ExtentReports("C:\\Users\\ramesh\\Desktop\\DemoReports\\report1.html");
                   ExtentTest logger=ext.startTest("Gmail Test");                  
                   System.setProperty("webdriver.gecko.driver", "C:\\Users\\ramesh\\Desktop\\desktop1\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
                   WebDriver driver=new FirefoxDriver();
                   driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);                                                        
                   driver.manage().window().maximize();
                   logger.log(LogStatus.INFO, "Browser is maximized");
                   driver.get("https://www.gmail.com");
                   logger.log(LogStatus.INFO, "URL is passed");

                   driver.findElement(By.id("Email")).sendKeys("atsunithase@gmail.com");
                   logger.log(LogStatus.INFO, "Uname is passed");

                   driver.findElement(By.id("next")).click();
                   logger.log(LogStatus.INFO, "Clicked on Next button");

                   Thread.sleep(2000);
                   driver.findElement(By.id("Passwd")).sendKeys("******");
                   logger.log(LogStatus.INFO, "Password is passed");

                   driver.findElement(By.id("signIn")).click();
                  
                   logger.log(LogStatus.INFO, "Clicked on signIn button");

                   //logger.log(LogStatus.INFO, "closed the browser");
                  
          ext.endTest(logger);
          ext.flush();

          driver.get("file:///C:/Users/ramesh/Desktop/DemoReports/report1.html");
                   }

}

NOTE: If we want we can add screenshots as well to our reports
       ext.addScreenCapture("");
 

 

No comments:

Post a Comment