This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testngpractice; | |
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.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import com.relevantcodes.extentreports.ExtentReports; | |
import com.relevantcodes.extentreports.ExtentTest; | |
import com.relevantcodes.extentreports.LogStatus; | |
public class BaseClassDemo { | |
static ExtentTest test; | |
static ExtentReports report; | |
@BeforeClass | |
public static void startTest() { | |
report = new ExtentReports(System.getProperty("user.dir") + "\\ExtentReportResults.html"); | |
test = report.startTest("ExtentDemo"); | |
} | |
@AfterClass | |
public static void endTest() { | |
report.endTest(test); | |
report.flush(); | |
} | |
public static String capture(WebDriver driver) throws IOException { | |
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); | |
File Dest = new File("src/../Images/" + System.currentTimeMillis() + ".png"); | |
String errflpath = Dest.getAbsolutePath(); | |
FileUtils.copyFile(scrFile, Dest); | |
return errflpath; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testngpractice; | |
import java.io.IOException; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.testng.annotations.Test; | |
import com.relevantcodes.extentreports.LogStatus; | |
public class ExtentTest extends BaseClassDemo { | |
@Test | |
public void extentReportsDemo() throws IOException { | |
System.setProperty("webdriver.chrome.driver","C:\\Users\\diya-mutturajh\\Desktop\\chromedriver\\chromedriver.exe"); | |
WebDriver driver = new ChromeDriver(); | |
driver.get("https://www.google.co.in"); | |
if (driver.getTitle().equals("Goog")) { | |
test.log(LogStatus.PASS, "Navigated to the specified URL"); | |
} else { | |
test.log(LogStatus.FAIL, "Test Failed"); | |
test.log(LogStatus.FAIL,test.addScreenCapture(capture(driver))+ "Test Failed"); | |
} | |
driver.close(); | |
driver.quit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports --> | |
<dependency> | |
<groupId>com.relevantcodes</groupId> | |
<artifactId>extentreports</artifactId> | |
<version>2.41.2</version> | |
</dependency> |
No comments:
Post a Comment