请在下面找到我使用 ExtentReport 3.0.6 和 selenium 3.4.0 的代码。屏幕截图没有保存,但我没有得到任何例外。它不保存任何屏幕截图。我不确定为什么会发生这种情况,几天前它对我有用。
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
WebDriver driver;
@BeforeTest
public void setUp()
{
//where we need to generate the report
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("My Test Report");
htmlReporter.config().setReportName("Test Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
@Test
public void demoReportPass()
{
test = extent.createTest("demoScreenshotTest");
System.setProperty("webdriver.chrome.driver","C:\\SeleniumServer\\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://www.google.com/");
String title = driver.getTitle();
Assert.assertEquals(title, "Goo");
}
@AfterMethod
public void getResult(ITestResult result) throws IOException
{
if(result.getStatus()==ITestResult.FAILURE)
{
String screenshotPath = capture(driver, "screenshotname");
//String screenshotPath = GetScreenshot.captureFullPage(driver, "screenshotname");
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test Case failed due to below issues", ExtentColor.RED));
test.fail(result.getThrowable());
test.fail("Snapshot below: " + test.addScreenCaptureFromPath(screenshotPath));
}
}
@AfterSuite
public void tearDown()
{
extent.flush();
driver.quit();
}
public String capture(WebDriver driver, String screenShotName) throws IOException
{
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest = "../test-output/"+screenShotName+".png";
File destination = new File(dest);
FileUtils.copyFile(source, destination);
return dest;
}