use of com.seleniumtests.reporter.info.HyperlinkInfo in project seleniumRobot by bhecquet.
the class BugTrackerReporter method generateReport.
@Override
protected void generateReport(Map<ITestContext, Set<ITestResult>> resultSet, String outdir, boolean optimizeReport, boolean finalGeneration) {
for (Map.Entry<ITestContext, Set<ITestResult>> entry : resultSet.entrySet()) {
ITestContext context = entry.getKey();
for (ITestResult testResult : entry.getValue()) {
// record only when all executions of a test method are done so that intermediate results (a failed test which has been retried) are not present in list
if (!Boolean.TRUE.equals(TestNGResultUtils.getNoMoreRetry(testResult)) || TestNGResultUtils.isBugtrackerReportCreated(testResult)) {
continue;
}
// done in case it was null (issue #81)
SeleniumTestsContext testContext = SeleniumTestsContextManager.setThreadContextFromTestResult(context, testResult);
BugTracker bugtrackerServer = testContext.getBugTrackerInstance();
if (bugtrackerServer == null) {
return;
}
// get all bugtracker options
Map<String, String> issueOptions = new HashMap<>();
for (TestVariable variable : testContext.getConfiguration().values()) {
if (variable.getName().startsWith("bugtracker.")) {
issueOptions.put(variable.getName().replace("bugtracker.", ""), variable.getValue());
}
}
// application data
String application = testContext.getApplicationName();
String environment = testContext.getTestEnv();
String testNgName = testResult.getTestContext().getCurrentXmlTest().getName();
String testName = TestNGResultUtils.getUniqueTestName(testResult);
String description = String.format("Test '%s' failed\n", testName);
if (testResult.getMethod().getDescription() != null && !testResult.getMethod().getDescription().trim().isEmpty()) {
description += "Test goal: " + TestNGResultUtils.getTestDescription(testResult);
}
// search the last step to get screenshots and failure reason
List<TestStep> testSteps = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
if (testSteps == null) {
return;
}
// create issue only for failed tests and if it has not been created before
if (testResult.getStatus() == ITestResult.FAILURE) {
IssueBean issueBean = bugtrackerServer.createIssue(application, environment, testNgName, testName, description, testSteps, issueOptions);
// log information on issue
if (issueBean != null) {
if (issueBean.getId() != null && issueBean.getAccessUrl() != null) {
TestNGResultUtils.setTestInfo(testResult, "Issue", new HyperlinkInfo(issueBean.getId(), issueBean.getAccessUrl()));
} else if (issueBean.getId() != null) {
TestNGResultUtils.setTestInfo(testResult, "Issue", new StringInfo(issueBean.getId()));
}
TestNGResultUtils.setTestInfo(testResult, "Issue date", new StringInfo(issueBean.getCreationDate()));
}
TestNGResultUtils.setBugtrackerReportCreated(testResult, true);
// close issue if test is now OK and a previous issue has been created
} else if (testResult.getStatus() == ITestResult.SUCCESS) {
bugtrackerServer.closeIssue(application, environment, testNgName, testName);
TestNGResultUtils.setBugtrackerReportCreated(testResult, true);
}
}
}
}
use of com.seleniumtests.reporter.info.HyperlinkInfo in project seleniumRobot by bhecquet.
the class StubTestClass method testWithInfo2.
@Test(groups = "stub", description = "a test with infos")
public void testWithInfo2() throws IOException {
TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
step1.addAction(new TestAction("click button", false, new ArrayList<>()));
step1.addAction(new TestAction("sendKeys to text field", true, new ArrayList<>()));
TestStepManager.logTestStep(step1);
addTestInfo("user ID", new HyperlinkInfo("12345", "http://foo/bar/12345"));
}
Aggregations