@Override public void onConfigurationFailure(ITestResult iTestResult) { super.onConfigurationFailure(iTestResult); String testName = iTestResult.getTestClass().getName(); String configurationName = iTestResult.getMethod().toString().split("\\(|\\)")[0]; if (!enableLogstash && isAfter(iTestResult)) { DumpUtils.copyBeforeConfigurationsLogToTestDir(testName, suiteName); testName = testMethodName; } if (suiteName == null) { // this is in case the suite has a @BeforeSuite method. which is invoked before // the onStart is. suiteName = System.getProperty("iTests.suiteName", "sgtest"); } LogUtils.log("Configuration Failed: " + configurationName, iTestResult.getThrowable()); if (enableLogstash && iTestResult.getMethod().isBeforeClassConfiguration()) { initLogstash2(iTestResult); } String newmanTestFolder = System.getProperty("newman.test.path"); if (newmanTestFolder != null) { File testFolder = new File(newmanTestFolder); ZipUtils.unzipArchive(testFolder); try { copyAllFilesToLogDir(testFolder, testFolder); } catch (IOException e) { LogUtils.log("Failed to copy all log files"); } } else { ZipUtils.unzipArchive(testMethodName, suiteName); } if (enableLogstash && isAfter(iTestResult) && !iTestResult.getMethod().isAfterClassConfiguration() && !iTestResult.getMethod().isAfterSuiteConfiguration()) { testName = testMethodName; } File testFolder = DumpUtils.createTestFolder(testName, suiteName); write2LogFile(iTestResult, testFolder); write2ErrorTxtFile(iTestResult, testFolder); if (isAfter(iTestResult)) { if (enableLogstash) { if (process != null) { killLogstashAgent(1, logstashLogPath); } if (process2 != null && iTestResult.getMethod().isAfterClassConfiguration()) { killLogstashAgent(2, logstashLogPath2); } } } }
private boolean isAfter(ITestResult iTestResult) { ITestNGMethod method = iTestResult.getMethod(); return (method.isAfterClassConfiguration() || method.isAfterMethodConfiguration() || method.isAfterSuiteConfiguration() || method.isAfterTestConfiguration()); }
// returns an ID for each test result private int getTestId(ITestResult result) { int id = result.getTestClass().getName().hashCode(); id = 31 * id + result.getMethod().getMethodName().hashCode(); id = 31 * id + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0); return id; }