Search in sources :

Example 1 with BugTracker

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);
            }
        }
    }
}
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 BugTracker

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());
}
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 3 with BugTracker

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");
}
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 4 with BugTracker

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);
}
Also used : 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 BugTracker

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));
}
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

BugTracker (com.seleniumtests.connectors.bugtracker.BugTracker)13 MockitoTest (com.seleniumtests.MockitoTest)12 FakeBugTracker (com.seleniumtests.connectors.bugtracker.FakeBugTracker)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 IssueBean (com.seleniumtests.connectors.bugtracker.IssueBean)10 JiraConnector (com.seleniumtests.connectors.bugtracker.jira.JiraConnector)1 SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)1 TestVariable (com.seleniumtests.core.TestVariable)1 HyperlinkInfo (com.seleniumtests.reporter.info.HyperlinkInfo)1 StringInfo (com.seleniumtests.reporter.info.StringInfo)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 SeleniumTestsReporter2 (com.seleniumtests.reporter.reporters.SeleniumTestsReporter2)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ITestContext (org.testng.ITestContext)1 ITestResult (org.testng.ITestResult)1