Search in sources :

Example 1 with HyperlinkInfo

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

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"));
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) TestAction(com.seleniumtests.reporter.logger.TestAction) HyperlinkInfo(com.seleniumtests.reporter.info.HyperlinkInfo) Test(org.testng.annotations.Test)

Aggregations

HyperlinkInfo (com.seleniumtests.reporter.info.HyperlinkInfo)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 BugTracker (com.seleniumtests.connectors.bugtracker.BugTracker)1 IssueBean (com.seleniumtests.connectors.bugtracker.IssueBean)1 SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)1 TestVariable (com.seleniumtests.core.TestVariable)1 StringInfo (com.seleniumtests.reporter.info.StringInfo)1 TestAction (com.seleniumtests.reporter.logger.TestAction)1 ArrayList (java.util.ArrayList)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 Test (org.testng.annotations.Test)1