Extent Reports in Selenium
Pre-requisites to Generate Extent Reports:
1 Download Extent Reports jar file and add it to the Project.
2. Create an ExtendReport object and give the path where you want to store the report
Ex: ExtentReports ext=new ExtentReports("C:\\Reports\\report1.html");
3. Retrive the ExtentTest object
Ex: ExtentTest logger=ext.startTest("Extend Report 2 Test");
4.Log the reports
Ex: logger.log(LogStatus.INFO, "Navigate to the URL");
5.End the Test and call flush().
Ex: ext.endTest(logger);
ext.flush()
Sample Code: Senario Taken-- Type some text in the text box(Search box in this example) and perform Copy and Paste using Chord and Keys
package com.p1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ExtendReports2 {
public WebDriver driver;
ExtentReports ext=new ExtentReports("G:\\Selenium\\extendReports\\Reports\\report1.html");
ExtentTest logger=ext.startTest("Extend Report 2 Test");
@Test
public void testKeys_Chord() {
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
//Object for the search box
WebElement sb=driver.findElement(By.xpath(".//*[@id='BlogSearch1_form']/form/table/tbody/tr/td[1]/input"));
//Type "The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver" in search box
sb.sendKeys("The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver ");
logger.log(LogStatus.INFO, "Typed the text in the search box");
//Perform Control A and C actions
sb.sendKeys(Keys.chord(Keys.CONTROL,"a"), "");
logger.log(LogStatus.INFO, "Performed the keyboard action Control A");
sb.sendKeys(Keys.chord(Keys.CONTROL,"c"), "");
logger.log(LogStatus.INFO, "Performed the keyboard action Control C");
//Clear the Text 'The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver' typed in the Search box
sb.clear();
logger.log(LogStatus.INFO, "Cleared the search box");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Perform paste action using CTRL+V in search box
sb.sendKeys(Keys.chord(Keys.CONTROL, "v"), "");
logger.log(LogStatus.INFO, "Pasted the copied content in the search box");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.xpath(".//*[@id='BlogSearch1_form']/form/table/tbody/tr/td[2]/input")).click();
logger.log(LogStatus.INFO, "Clicked the Search button");
}
@BeforeClass
public void beforeClass()
{
System.setProperty("webdriver.gecko.driver", "G://Selenium//geckodriver-v0.19.1-win32//geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("http://allthingsaboutuft.blogspot.in/");
logger.log(LogStatus.INFO, "Launched the URL");
driver.manage().window().maximize();
logger.log(LogStatus.INFO, "Browser is maximized");
}
@AfterClass
public void afterClass() throws Exception
{
logger.log(LogStatus.INFO, "Report is opened");
ext.endTest(logger);
ext.flush();
driver.get("file:///G:/Selenium/extendReports/Reports/report1.html");
}
}
Pre-requisites to Generate Extent Reports:
1 Download Extent Reports jar file and add it to the Project.
2. Create an ExtendReport object and give the path where you want to store the report
Ex: ExtentReports ext=new ExtentReports("C:\\Reports\\report1.html");
3. Retrive the ExtentTest object
Ex: ExtentTest logger=ext.startTest("Extend Report 2 Test");
4.Log the reports
Ex: logger.log(LogStatus.INFO, "Navigate to the URL");
5.End the Test and call flush().
Ex: ext.endTest(logger);
ext.flush()
Sample Code: Senario Taken-- Type some text in the text box(Search box in this example) and perform Copy and Paste using Chord and Keys
package com.p1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ExtendReports2 {
public WebDriver driver;
ExtentReports ext=new ExtentReports("G:\\Selenium\\extendReports\\Reports\\report1.html");
ExtentTest logger=ext.startTest("Extend Report 2 Test");
@Test
public void testKeys_Chord() {
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
//Object for the search box
WebElement sb=driver.findElement(By.xpath(".//*[@id='BlogSearch1_form']/form/table/tbody/tr/td[1]/input"));
//Type "The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver" in search box
sb.sendKeys("The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver ");
logger.log(LogStatus.INFO, "Typed the text in the search box");
//Perform Control A and C actions
sb.sendKeys(Keys.chord(Keys.CONTROL,"a"), "");
logger.log(LogStatus.INFO, "Performed the keyboard action Control A");
sb.sendKeys(Keys.chord(Keys.CONTROL,"c"), "");
logger.log(LogStatus.INFO, "Performed the keyboard action Control C");
//Clear the Text 'The mouse-over using JavascriptExecutor and Actions in Selenium Webdriver' typed in the Search box
sb.clear();
logger.log(LogStatus.INFO, "Cleared the search box");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Perform paste action using CTRL+V in search box
sb.sendKeys(Keys.chord(Keys.CONTROL, "v"), "");
logger.log(LogStatus.INFO, "Pasted the copied content in the search box");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.xpath(".//*[@id='BlogSearch1_form']/form/table/tbody/tr/td[2]/input")).click();
logger.log(LogStatus.INFO, "Clicked the Search button");
}
@BeforeClass
public void beforeClass()
{
System.setProperty("webdriver.gecko.driver", "G://Selenium//geckodriver-v0.19.1-win32//geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("http://allthingsaboutuft.blogspot.in/");
logger.log(LogStatus.INFO, "Launched the URL");
driver.manage().window().maximize();
logger.log(LogStatus.INFO, "Browser is maximized");
}
@AfterClass
public void afterClass() throws Exception
{
logger.log(LogStatus.INFO, "Report is opened");
ext.endTest(logger);
ext.flush();
driver.get("file:///G:/Selenium/extendReports/Reports/report1.html");
}
}
Reprot:
Graphical Report:
No comments:
Post a Comment