package com.hexaware.parabank; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; public class hook { ExtentTest test; ExtentReports report; public WebDriver driver; @BeforeClass public void setup() { System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+ "\\drivers\\chromedriver.exe" ); ChromeOptions options = new ChromeOptions(); options.addArguments("--ignore-ssl-errors=yes"); options.addArguments("--ignore-certificate-errors"); options.addArguments("disable-infobars"); options.addArguments("--remote-allow-origins=*"); options.setAcceptInsecureCerts(true); driver= new ChromeDriver(options); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); report = new ExtentReports(System.getProperty("user.dir")+"\\ExtentReportResults.html"); test = report.startTest("ExtentDemo"); } public String capture(WebDriver driver) throws IOException { File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); File Dest = new File("src/../Screenshots/" + System.currentTimeMillis() + ".png"); String errflpath = Dest.getAbsolutePath(); FileUtils.copyFile(scrFile, Dest); return errflpath; } @AfterClass public void tearDown() throws InterruptedException { Thread.sleep(5000); driver.quit(); report.endTest(test); report.flush(); } }