未生成范围报告版本 4 屏幕截图
extent report version 4 screenshot not generating
我根本不明白为什么会出现这个错误。无法生成范围报告和捕获屏幕截图。我附加了测试、AfterMethod 和 AfterTest 以及屏幕截图方法。我想在不同的文件夹下捕获屏幕截图。
我收到的错误信息如下。
FAILED CONFIGURATION: @AfterMethod getReport([TestResult
name=checkTitle status=SUCCESS method=Google.checkTitle()[pri:0,
instance:Google@3224f60b] output={null}]) java.io.IOException: The
filename, directory name, or volume label syntax is incorrect hod.
以下是我的硒测试代码。
@Test
public void checkTitle() {
test = extent.createTest("Title Check test");
Actual_Title = driver.getTitle();
System.out.println(Actual_Title);
Assert.assertEquals(Actual_Title, Expected_Tite);
test.log(Status.PASS, "This Test is Passed!");
}
@AfterMethod
public void getReport(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.RED));
test.fail("TestFailed due to"+" "+result.getThrowable().getMessage());
String imagePath =Google.captureScreen(driver,result.getName());
test.addScreenCaptureFromPath(imagePath);
}
else if (result.getStatus() == ITestResult.SKIP) {
test.log(Status.SKIP,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.AMBER));
test.skip(result.getThrowable().getMessage());
} else {
test.log(Status.PASS,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.GREEN));
String imagePath =Google.captureScreen(driver, result.getName());
test.addScreenCaptureFromPath(imagePath);
}
}
@AfterTest
public void endTest() {
extent.flush();
driver.quit();
}
public static String captureScreen(WebDriver driver,String screenshotname)throws IOException {
String date = new SimpleDateFormat("MM-dd-yy,hh:mm:ss").format(new Date());
TakesScreenshot ts = (TakesScreenshot)driver;
File src= ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/ScreenShots/"+screenshotname+date+".png";
File destination = new File(path);
FileUtils.copyFile(src, destination);
return path;
}
我可以重现你的问题。
对于下面的代码,我遇到了与您提到的完全相同的错误。
String date = new SimpleDateFormat("MM-dd-yy,hh:mm:ss").format(new Date());
String screenshotname = "MyScreenshot";
String path = System.getProperty("user.dir")+"/test-
output/"+screenshotname+date+".png";
logger.info("In failedTCTakeScreenshot:: ******path***** " + path);
日志错误
[INFO ] 2020-07-28 23:09:52.281 [main] com.resources.BaseTest -In
failedTCTakeScreenshot:: ******path*****
E:\Automation\EclipseWorkspace\AutomationPrj/test-output/MyScreenshot07-28-
20,11:09:52.png
[ERROR] 2020-07-28 23:09:52.285 [main] com.resources.BaseTest -
BaseTest::failedTCTakeScreenshot::***In Catch Block *** java.io.IOException: The
filename, directory name, or volume label syntax is incorrect
根本原因分析:-
经分析,我发现,您存储的屏幕截图名称为 MM-dd-yy,hh:mm:ss 日期格式。 Windows 不接受文件名中的任何 : 或 , 。您需要更改您的屏幕截图名称,使其不包含 : 等
当我将代码中的 DateFormat 更改为 MM-dd-yyyy 时,我可以成功复制屏幕截图并且没有抛出任何错误。
String date = new SimpleDateFormat("MM-dd-yyyy").format(new Date());
String screenshotname = "MyScreenshot";
String path = System.getProperty("user.dir")+"/test-
output/"+screenshotname+date+".png";
logger.info("In failedTCTakeScreenshot:: ******path***** " + path);
日志:-
[INFO ] 2020-07-28 23:24:27.457 [main] com.resources.BaseTest - In
failedTCTakeScreenshot:: ******path*****
E:\Automation\EclipseWorkspace\AutomationPrj/test-output/MyScreenshot07-28-
2020.png
[INFO ] 2020-07-28 23:24:27.463 [main] com.resources.BaseTest - In
failedTCTakeScreenshot:: ******path destination*****
E:\Automation\EclipseWorkspace\AutomationPrj\test-output\MyScreenshot07-28-
2020.png
因此您只需要更改屏幕截图名称,使其不应该包含特殊字符,如 ;并且,
我根本不明白为什么会出现这个错误。无法生成范围报告和捕获屏幕截图。我附加了测试、AfterMethod 和 AfterTest 以及屏幕截图方法。我想在不同的文件夹下捕获屏幕截图。
我收到的错误信息如下。
FAILED CONFIGURATION: @AfterMethod getReport([TestResult name=checkTitle status=SUCCESS method=Google.checkTitle()[pri:0, instance:Google@3224f60b] output={null}]) java.io.IOException: The filename, directory name, or volume label syntax is incorrect hod.
以下是我的硒测试代码。
@Test
public void checkTitle() {
test = extent.createTest("Title Check test");
Actual_Title = driver.getTitle();
System.out.println(Actual_Title);
Assert.assertEquals(Actual_Title, Expected_Tite);
test.log(Status.PASS, "This Test is Passed!");
}
@AfterMethod
public void getReport(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.RED));
test.fail("TestFailed due to"+" "+result.getThrowable().getMessage());
String imagePath =Google.captureScreen(driver,result.getName());
test.addScreenCaptureFromPath(imagePath);
}
else if (result.getStatus() == ITestResult.SKIP) {
test.log(Status.SKIP,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.AMBER));
test.skip(result.getThrowable().getMessage());
} else {
test.log(Status.PASS,MarkupHelper.createLabel(result.getMethod().getMethodName(),ExtentColor.GREEN));
String imagePath =Google.captureScreen(driver, result.getName());
test.addScreenCaptureFromPath(imagePath);
}
}
@AfterTest
public void endTest() {
extent.flush();
driver.quit();
}
public static String captureScreen(WebDriver driver,String screenshotname)throws IOException {
String date = new SimpleDateFormat("MM-dd-yy,hh:mm:ss").format(new Date());
TakesScreenshot ts = (TakesScreenshot)driver;
File src= ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/ScreenShots/"+screenshotname+date+".png";
File destination = new File(path);
FileUtils.copyFile(src, destination);
return path;
}
我可以重现你的问题。 对于下面的代码,我遇到了与您提到的完全相同的错误。
String date = new SimpleDateFormat("MM-dd-yy,hh:mm:ss").format(new Date());
String screenshotname = "MyScreenshot";
String path = System.getProperty("user.dir")+"/test-
output/"+screenshotname+date+".png";
logger.info("In failedTCTakeScreenshot:: ******path***** " + path);
日志错误
[INFO ] 2020-07-28 23:09:52.281 [main] com.resources.BaseTest -In
failedTCTakeScreenshot:: ******path*****
E:\Automation\EclipseWorkspace\AutomationPrj/test-output/MyScreenshot07-28-
20,11:09:52.png
[ERROR] 2020-07-28 23:09:52.285 [main] com.resources.BaseTest -
BaseTest::failedTCTakeScreenshot::***In Catch Block *** java.io.IOException: The
filename, directory name, or volume label syntax is incorrect
根本原因分析:-
经分析,我发现,您存储的屏幕截图名称为 MM-dd-yy,hh:mm:ss 日期格式。 Windows 不接受文件名中的任何 : 或 , 。您需要更改您的屏幕截图名称,使其不包含 : 等
当我将代码中的 DateFormat 更改为 MM-dd-yyyy 时,我可以成功复制屏幕截图并且没有抛出任何错误。
String date = new SimpleDateFormat("MM-dd-yyyy").format(new Date());
String screenshotname = "MyScreenshot";
String path = System.getProperty("user.dir")+"/test-
output/"+screenshotname+date+".png";
logger.info("In failedTCTakeScreenshot:: ******path***** " + path);
日志:-
[INFO ] 2020-07-28 23:24:27.457 [main] com.resources.BaseTest - In
failedTCTakeScreenshot:: ******path*****
E:\Automation\EclipseWorkspace\AutomationPrj/test-output/MyScreenshot07-28-
2020.png
[INFO ] 2020-07-28 23:24:27.463 [main] com.resources.BaseTest - In
failedTCTakeScreenshot:: ******path destination*****
E:\Automation\EclipseWorkspace\AutomationPrj\test-output\MyScreenshot07-28-
2020.png
因此您只需要更改屏幕截图名称,使其不应该包含特殊字符,如 ;并且,