Search in sources :

Example 66 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestStep method testTestStepWithrootCause.

@Test(groups = { "ut" })
public void testTestStepWithrootCause() {
    TestStep step = new TestStep("step1", null, new ArrayList<>(), true, RootCause.REGRESSION, "details", false);
    // mandatory so that errorCauseDetails is not null
    step.setFailed(true);
    Assert.assertEquals(step.getRootCause(), RootCause.REGRESSION);
    Assert.assertEquals(step.getRootCauseDetails(), "details");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 67 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class Uft method addStepWithoutXml.

private void addStepWithoutXml(List<TestStep> listStep, String messageException, Exception e) {
    logger.error(messageException + e.getMessage());
    TestStep readStep = new TestStep("UFT: " + scriptName, Reporter.getCurrentTestResult(), new ArrayList<>(), false);
    readStep.addMessage(new TestMessage(messageException + e.getMessage(), MessageType.ERROR));
    listStep.add(readStep);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TestMessage(com.seleniumtests.reporter.logger.TestMessage)

Example 68 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class Uft method readStep.

/**
 * Read a step element
 * <p>
 * // * @param parentStep
 *
 * @param stepElement
 */
private TestAction readStep(Element stepElement) {
    TestAction stepAction;
    List<Element> stepList = stepElement.getChildren("Step");
    org.jsoup.nodes.Document htmlDoc = Jsoup.parseBodyFragment(stepElement.getChildText("Details"));
    String details = htmlDoc.text();
    String stepDescription = String.format("%s: %s", stepElement.getChildText("Obj"), details).trim();
    if (stepList.isEmpty()) {
        stepAction = new TestAction(stepDescription, false, new ArrayList<>());
    } else {
        stepAction = new TestStep(stepDescription, Reporter.getCurrentTestResult(), new ArrayList<>(), false);
        for (Element subStepElement : stepElement.getChildren("Step")) {
            TestAction readAction = readStep(subStepElement);
            ((TestStep) stepAction).addAction(readAction);
        }
    }
    return stepAction;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) TestAction(com.seleniumtests.reporter.logger.TestAction)

Example 69 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class BugTracker method createIssueBean.

/**
 * Create an issue object
 * @param testName			method name (name of scenario)
 * @param description		Description of the test. May be null
 * @param testSteps			Test steps of the scenario
 * @param issueOptions		options for the new issue
 * @return
 */
public IssueBean createIssueBean(String summary, String testName, String description, List<TestStep> testSteps, Map<String, String> issueOptions) {
    TestStep lastTestStep = null;
    List<TestStep> failedSteps = new ArrayList<>();
    for (TestStep testStep : testSteps) {
        // "Test end" step should never be considered as failed, because it reflects the overall test result
        if (Boolean.TRUE.equals(testStep.getFailed()) && !testStep.isTestEndStep() && // if the step has the flag disabling bugtracker, do not count it as failed step
        !testStep.isDisableBugtracker()) {
            failedSteps.add(testStep);
        }
        if (testStep.isTestEndStep()) {
            lastTestStep = testStep;
            break;
        }
    }
    // don't create issue if no failed step is present
    if (failedSteps.isEmpty()) {
        logger.info("No failed steps. It may be due to a failed step marked as disabled for bugtracker");
        return null;
    }
    // don't create issue if test has not been executed or not completed
    if (lastTestStep == null) {
        return null;
    }
    List<ScreenShot> screenShots = lastTestStep.getSnapshots().stream().map(Snapshot::getScreenshot).collect(Collectors.toList());
    StringBuilder fullDescription = new StringBuilder();
    formatDescription(testName, failedSteps, lastTestStep, description, fullDescription);
    File zipFile = null;
    // provide detailedResult.zip file only when 'startedBy' is not present. This prevent from sending big reports to bugtracker
    if (SeleniumTestsContextManager.getThreadContext().getStartedBy() == null) {
        fullDescription.append("\n\nFor more details, see attached .zip file");
        zipFile = createDetailedResultReport(testName);
    }
    String assignee = issueOptions.get("assignee");
    String reporter = issueOptions.get("reporter");
    return createIssueBean(summary, fullDescription.toString(), testName, // take the last failed step as step we will show as failed even if there are several
    failedSteps.isEmpty() ? lastTestStep : failedSteps.get(failedSteps.size() - 1), assignee, reporter, screenShots, zipFile, issueOptions);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File)

Example 70 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class BugTracker method formatDescription.

/**
 * Format description
 * For any bugtracker, description is quite simple but it can be improved depending on bug tracker
 * /!\ any method overriding this one MUST provide "STEP_KO_PATTERN" in the description because it's used to know if the failed step is the same
 *
 * @param testSteps
 * @param fullDescription
 * @param screenShots
 * @return
 */
protected void formatDescription(String testName, List<TestStep> failedSteps, TestStep lastTestStep, String description, StringBuilder fullDescription) {
    fullDescription.append(String.format("Test: %s\n", testName));
    if (description != null) {
        fullDescription.append(String.format("Description: %s\n", description));
    }
    if (SeleniumTestsContextManager.getThreadContext().getStartedBy() != null) {
        fullDescription.append(String.format("Started by: %s\n", SeleniumTestsContextManager.getThreadContext().getStartedBy()));
    }
    for (TestStep failedStep : failedSteps) {
        fullDescription.append(String.format("Error step %d (%s): %s\n", failedStep.getPosition(), failedStep.getName(), failedStep.getActionException()));
    }
    fullDescription.append("\n");
    if (!failedSteps.isEmpty()) {
        fullDescription.append("Steps in error\n");
        for (TestStep failedStep : failedSteps) {
            fullDescription.append(String.format(STEP_KO_PATTERN + "%s\n", failedStep.getPosition(), failedStep.getName()));
            fullDescription.append("------------------------------------\n");
            fullDescription.append(failedStep.toString() + "\n\n");
        }
    }
    fullDescription.append("Last logs\n");
    fullDescription.append(lastTestStep.toString());
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep)

Aggregations

TestStep (com.seleniumtests.reporter.logger.TestStep)190 Test (org.testng.annotations.Test)148 GenericTest (com.seleniumtests.GenericTest)120 ArrayList (java.util.ArrayList)80 TestAction (com.seleniumtests.reporter.logger.TestAction)47 File (java.io.File)37 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)25 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)19 TestMessage (com.seleniumtests.reporter.logger.TestMessage)16 GenericFile (com.seleniumtests.reporter.logger.GenericFile)15 MockitoTest (com.seleniumtests.MockitoTest)12 HashMap (java.util.HashMap)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 ITestResult (org.testng.ITestResult)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Uft (com.seleniumtests.connectors.extools.Uft)8 DriverExceptions (com.seleniumtests.customexception.DriverExceptions)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)6