Selenium测试用例通过方法后获取错误来停止

时间:2017-09-15 05:25:06

标签: java selenium testng selenium-extent-report

我有一个项目,我使用Testng并使用扩展报告进行报告。我总共有64个测试用例但是当24个测试用例时,运行我的after方法时,显示错误并停止执行。我们可以继续执行吗? / p>

  

是否有任何建议我如何能够停止执行

这是我的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)

0 个答案:

没有答案