コード例 #1
0
 @Override
 public void onTestFailure(ITestResult iTestResult) {
   if (suiteName.toLowerCase().contains("webui")) {
     if (testInvocationCounter < maxCount) {
       testInvocationCounter++;
       iTestResult.setAttribute("retry", true);
     } else {
       LogUtils.log("Number of retries expired.");
       iTestResult.setStatus(ITestResult.FAILURE);
       // reset count
       testInvocationCounter = 1;
       testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
       LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
       File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
       write2LogFile(iTestResult, testFolder);
       write2ErrorTxtFile(iTestResult, testFolder);
     }
   } else {
     testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
     LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
     File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
     write2LogFile(iTestResult, testFolder);
     write2ErrorTxtFile(iTestResult, testFolder);
   }
   super.onTestFailure(iTestResult);
 }
コード例 #2
0
 @Override
 public void onTestSkipped(ITestResult iTestResult) {
   super.onTestSkipped(iTestResult);
   testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Skipped: " + testMethodName, iTestResult.getThrowable());
   write2LogFile(iTestResult, DumpUtils.createTestFolder(testMethodName, suiteName));
 }
コード例 #3
0
 @Override
 public void onTestStart(ITestResult iTestResult) {
   super.onTestStart(iTestResult);
   String testName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Start: " + testName);
   if (enableLogstash) {
     initLogstash(testName);
   }
 }
コード例 #4
0
 @Override
 public void onTestSuccess(ITestResult iTestResult) {
   super.onTestSuccess(iTestResult);
   if (suiteName.toLowerCase().contains("webui")) {
     testInvocationCounter = 1;
   }
   testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Passed: " + testMethodName);
   write2LogFile(iTestResult, DumpUtils.createTestFolder(testMethodName, suiteName));
 }
コード例 #5
0
 private void write2LogFile(ITestResult iTestResult, File testFolder) {
   BufferedWriter out = null;
   try {
     if (testFolder == null) {
       LogUtils.log("Can not write to file test folder is null");
       return;
     }
     String output = SGTestNGReporter.getOutput();
     if (StringUtils.isEmpty(output)) {
       LogUtils.log("nothing to write to log file");
       return;
     }
     String parameters = TestNGUtils.extractParameters(iTestResult);
     File testLogFile =
         new File(
             testFolder.getAbsolutePath()
                 + "/"
                 + iTestResult.getName()
                 + "("
                 + parameters
                 + ").log");
     if (!testLogFile.createNewFile()) {
       LogUtils.log(
           "Failed to create log file ["
               + testLogFile
               + "];\n log output: "
               + Reporter.getOutput());
       return;
     }
     FileWriter fstream = new FileWriter(testLogFile);
     out = new BufferedWriter(fstream);
     out.write(output);
   } catch (Exception e) {
     LogUtils.log("Failed to write to log file result - " + iTestResult, e);
   } finally {
     SGTestNGReporter.reset();
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         LogUtils.log("Failed closing stream", e);
         // ignore
       }
     }
   }
 }