use of com.seleniumtests.connectors.bugtracker.BugTracker 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.BugTracker 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.BugTracker 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.BugTracker in project seleniumRobot by bhecquet.
the class TestBugTracker method testOnlyOneInstanceIsCreatedForSameUrl.
/**
* Check that if we request the same bugtracker N times (for same URL), it's always the same instance returned
* This is to avoid staled connections
* @throws Exception
*/
@Test(groups = { "ut" })
public void testOnlyOneInstanceIsCreatedForSameUrl() throws Exception {
BugTracker bugtracker1 = BugTracker.getInstance("fake", "http://foo/bar", "selenium", "user", "password", new HashMap<>());
BugTracker bugtracker2 = BugTracker.getInstance("fake", "http://foo/bar", "selenium", "user", "password", new HashMap<>());
Assert.assertEquals(bugtracker1, bugtracker2);
}
use of com.seleniumtests.connectors.bugtracker.BugTracker in project seleniumRobot by bhecquet.
the class TestBugTracker method testCreateIssue.
/**
* Create a new issue when there is a failed step
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCreateIssue() 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<>());
bugtracker.createIssue("selenium", "DEV", "ngName", "testCreateIssue", "some description", Arrays.asList(step2, stepEnd), issueOptions);
// check that we check if the issue already exists
verify(fbt).issueAlreadyExists(any(IssueBean.class));
// check that issue is created
verify(fbt).createIssue(any(IssueBean.class));
}
Aggregations