use of com.seleniumtests.connectors.bugtracker.IssueBean 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.connectors.bugtracker.IssueBean in project seleniumRobot by bhecquet.
the class JiraConnector method createIssue.
/**
* Create issue
*/
public void createIssue(IssueBean issueBean) {
if (!(issueBean instanceof JiraBean)) {
throw new ClassCastException("JiraConnector needs JiraBean instances");
}
JiraBean jiraBean = (JiraBean) issueBean;
IssueType issueType = issueTypes.get(jiraBean.getIssueType());
if (issueType == null) {
throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", jiraBean.getIssueType(), issueTypes.keySet()));
}
Map<String, CimFieldInfo> fieldInfos = getCustomFieldInfos(project, issueType);
IssueRestClient issueClient = restClient.getIssueClient();
IssueInputBuilder issueBuilder = new IssueInputBuilder(project, issueType, jiraBean.getSummary()).setDescription(jiraBean.getDescription());
if (isDueDateRequired(fieldInfos)) {
issueBuilder.setDueDate(jiraBean.getJodaDateTime());
}
if (jiraBean.getAssignee() != null && !jiraBean.getAssignee().isEmpty()) {
User user = getUser(jiraBean.getAssignee());
if (user == null) {
throw new ConfigurationException(String.format("Assignee %s cannot be found among jira users", jiraBean.getAssignee()));
}
issueBuilder.setAssignee(user);
}
if (jiraBean.getPriority() != null && !jiraBean.getPriority().isEmpty()) {
Priority priority = priorities.get(jiraBean.getPriority());
if (priority == null) {
throw new ConfigurationException(String.format("Priority %s cannot be found on this jira project, valid priorities are %s", jiraBean.getPriority(), priorities.keySet()));
}
issueBuilder.setPriority(priority);
}
if (jiraBean.getReporter() != null && !jiraBean.getReporter().isEmpty()) {
issueBuilder.setReporterName(jiraBean.getReporter());
}
// set fields
setCustomFields(jiraBean, fieldInfos, issueBuilder);
// set components
issueBuilder.setComponents(jiraBean.getComponents().stream().filter(component -> components.get(component) != null).map(component -> components.get(component)).collect(Collectors.toList()).toArray(new BasicComponent[] {}));
// add issue
IssueInput newIssue = issueBuilder.build();
BasicIssue basicIssue = issueClient.createIssue(newIssue).claim();
Issue issue = issueClient.getIssue(basicIssue.getKey()).claim();
addAttachments(jiraBean, issueClient, issue);
jiraBean.setId(issue.getKey());
jiraBean.setAccessUrl(browseUrl + issue.getKey());
}
use of com.seleniumtests.connectors.bugtracker.IssueBean in project seleniumRobot by bhecquet.
the class TestBugTracker method testCreateIssueBean.
/**
* Create a new issue bean
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCreateIssueBean() throws Exception {
// copy resources so that we can be sure something has been copied to zip file
new SeleniumTestsReporter2().copyResources();
FakeBugTracker fbt = spy(new FakeBugTracker());
PowerMockito.whenNew(FakeBugTracker.class).withAnyArguments().thenReturn(fbt);
BugTracker bugtracker = BugTracker.getInstance("fake", "http://foo/bar", "selenium", "user", "password", new HashMap<>());
IssueBean issueBean = bugtracker.createIssueBean("[Selenium][selenium][DEV][ngName] test myTest KO", "testCreateIssueBean", "some description", Arrays.asList(step1, step2, stepEnd), issueOptions);
Assert.assertEquals(issueBean.getAssignee(), "me");
Assert.assertEquals(issueBean.getDescription(), "Test: testCreateIssueBean\n" + "Description: some description\n" + "Error step 1 (step 2): java.lang.NullPointerException: Error clicking\n" + "\n" + "Steps in error\n" + "Step 1: step 2\n" + "------------------------------------\n" + "Step step 2\n" + " - action1\n" + " - action2\n" + "\n" + "Last logs\n" + "Step Test end\n" + "\n" + "For more details, see attached .zip file");
Assert.assertEquals(issueBean.getSummary(), "[Selenium][selenium][DEV][ngName] test myTest KO");
Assert.assertEquals(issueBean.getReporter(), "you");
Assert.assertEquals(issueBean.getTestName(), "testCreateIssueBean");
// screenshots from the last step
Assert.assertEquals(issueBean.getScreenShots(), Arrays.asList(screenshot, screenshot));
// we take the last failing step (not Test end)
Assert.assertEquals(issueBean.getTestStep(), step2);
Assert.assertEquals(issueBean.getDateTime().getDayOfMonth(), ZonedDateTime.now().plusHours(3).getDayOfMonth());
Assert.assertTrue(issueBean.getDetailedResult().isFile());
Assert.assertEquals(issueBean.getDetailedResult().getName(), "detailedResult.zip");
Assert.assertTrue(issueBean.getDetailedResult().length() > 900000);
// not initialized by default
Assert.assertNull(issueBean.getId());
}
use of com.seleniumtests.connectors.bugtracker.IssueBean in project seleniumRobot by bhecquet.
the class TestBugTracker method testCreateIssueBeanWithStepDisabled.
/**
* Test that if the failed step disables bugtracker, but an other keeps it enabled, the issue bean is created
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCreateIssueBeanWithStepDisabled() throws Exception {
FakeBugTracker fbt = spy(new FakeBugTracker());
PowerMockito.whenNew(FakeBugTracker.class).withAnyArguments().thenReturn(fbt);
BugTracker bugtracker = BugTracker.getInstance("fake", "http://foo/bar", "selenium", "user", "password", new HashMap<>());
IssueBean issueBean = bugtracker.createIssueBean("[Selenium][selenium][DEV][ngName] test myTest KO", "testCreateIssueBeanWithStepDisabled", "some description", Arrays.asList(step1, step2, stepFailedWithDisabledBugtracker, stepEnd), issueOptions);
Assert.assertNotNull(issueBean);
// check description only points step2 as the failed step
Assert.assertEquals(issueBean.getDescription(), "Test: testCreateIssueBeanWithStepDisabled\n" + "Description: some description\n" + "Error step 1 (step 2): java.lang.NullPointerException: Error clicking\n" + "\n" + "Steps in error\n" + "Step 1: step 2\n" + "------------------------------------\n" + "Step step 2\n" + " - action1\n" + " - action2\n" + "\n" + "Last logs\n" + "Step Test end\n" + "\n" + "For more details, see attached .zip file");
}
use of com.seleniumtests.connectors.bugtracker.IssueBean in project seleniumRobot by bhecquet.
the class TestBugTracker method testUpdateIssue.
/**
* Update an existing issue as we fail on an other step
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateIssue() throws Exception {
FakeBugTracker fbt = spy(new FakeBugTracker());
PowerMockito.whenNew(FakeBugTracker.class).withAnyArguments().thenReturn(fbt);
when(fbt.issueAlreadyExists(any(IssueBean.class))).thenReturn(new IssueBean("ISSUE-1", "[Selenium][app][env][ng] test Test1 KO", "Test KO"));
BugTracker bugtracker = BugTracker.getInstance("fake", "http://foo/bar", "selenium", "user", "password", new HashMap<>());
bugtracker.createIssue("selenium", "DEV", "ngName", "testUpdateIssue", "some description", Arrays.asList(step1, step2, stepEnd), issueOptions);
// check that we check if the issue already exists
verify(fbt).issueAlreadyExists(any(IssueBean.class));
// check that issue is not created
verify(fbt, never()).createIssue(any(IssueBean.class));
verify(fbt).updateIssue(eq("ISSUE-1"), anyString(), anyList(), eq(step2));
}
Aggregations