我有一个项目,我使用 Testng 并使用扩展报告进行报告。我总共有 64 个测试用例,但是当运行我的 after 方法时,24 个测试用例显示错误并停止执行。我们可以继续执行吗?
有什么建议我可以从停止执行中恢复过来吗
这是我的 after 方法类
@AfterMethod
public void setTestResult(ITestResult result) throws IOException {
String screenShot = CaptureScreenShot.captureScreen(wd, CaptureScreenShot.generateFileName(result));
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL, result.getName());
test.log(Status.FAIL,result.getThrowable());
test.fail("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, result.getName());
test.pass("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SKIP) {
test.skip("Test Case : " + result.getName() + " has been skipped");
}
extent.flush();
wd.quit();
}
这是我的 CaptureScreenShot 类
public class CaptureScreenShot {
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd SSS");
public static String captureScreen(WebDriver driver, String screenName) throws IOException{
TakesScreenshot screen = (TakesScreenshot) driver;
File src = screen.getScreenshotAs(OutputType.FILE);
String dest ="C:/xampp//htdocs/Automation_report/Test-ScreenShots"+screenName+".png";
File target = new File(dest);
FileUtils.copyFile(src, target);
return dest;
}
public static String generateFileName(ITestResult result){
Date date = new Date();
String fileName = result.getName()+ "_" + dateFormat.format(date);
return fileName;
}
}
我正在这样写测试用例
@test
public void DetailsPageRedirectToPartnerSite_VRBO() throws InterruptedException {
test = extent.createTest("Details PageRedirecToPartner Site");
}
我收到以下错误
java.nio.channels.ClosedByInterruptException
at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)
at sun.nio.ch.FileChannelImpl.size(FileChannelImpl.java:315)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1145)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1088)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1040)
at vrs.CaptureScreenShot.captureScreen(CaptureScreenShot.java:25)
at vrs.BedroomvillasProduction.setTestResult(BedroomvillasProduction.java:2320)
at sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:786)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:37)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)