Search in sources :

Example 1 with IssueBean

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);
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Set(java.util.Set) SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) HashMap(java.util.HashMap) TestVariable(com.seleniumtests.core.TestVariable) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) HyperlinkInfo(com.seleniumtests.reporter.info.HyperlinkInfo) ITestContext(org.testng.ITestContext) StringInfo(com.seleniumtests.reporter.info.StringInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IssueBean

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());
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) User(com.atlassian.jira.rest.client.api.domain.User) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

Example 3 with IssueBean

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());
}
Also used : FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) SeleniumTestsReporter2(com.seleniumtests.reporter.reporters.SeleniumTestsReporter2) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 4 with IssueBean

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");
}
Also used : FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 5 with IssueBean

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));
}
Also used : FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) FakeBugTracker(com.seleniumtests.connectors.bugtracker.FakeBugTracker) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

IssueBean (com.seleniumtests.connectors.bugtracker.IssueBean)18 MockitoTest (com.seleniumtests.MockitoTest)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Test (org.testng.annotations.Test)16 BugTracker (com.seleniumtests.connectors.bugtracker.BugTracker)9 JiraConnector (com.seleniumtests.connectors.bugtracker.jira.JiraConnector)9 FakeBugTracker (com.seleniumtests.connectors.bugtracker.FakeBugTracker)7 JiraBean (com.seleniumtests.connectors.bugtracker.jira.JiraBean)6 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)3 TestStep (com.seleniumtests.reporter.logger.TestStep)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)1 BasicComponent (com.atlassian.jira.rest.client.api.domain.BasicComponent)1 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)1 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)1 BasicProject (com.atlassian.jira.rest.client.api.domain.BasicProject)1