Search in sources :

Example 96 with TestStep

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

the class JiraConnector method formatDescription.

/**
 * Format description of the issue
 */
@Override
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.replace("Test goal:", "*Test goal:*")));
    }
    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):* *{color:#de350b}%s{color}*\n", failedStep.getPosition(), failedStep.getName(), failedStep.getActionException()));
    }
    formatFailedStep(failedSteps, fullDescription);
    fullDescription.append("h2. Last logs\n");
    if (lastTestStep != null) {
        fullDescription.append(String.format("{code:java}%s{code}", lastTestStep.toString()));
        fullDescription.append("\n\nh2. Associated screenshots\n");
        List<ScreenShot> screenshots = lastTestStep.getSnapshots().stream().map(Snapshot::getScreenshot).collect(Collectors.toList());
        for (ScreenShot screenshot : screenshots) {
            if (screenshot.getFullImagePath() != null && new File(screenshot.getFullImagePath()).exists()) {
                fullDescription.append(String.format("!%s|thumbnail!\n", new File(screenshot.getFullImagePath()).getName()));
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File)

Example 97 with TestStep

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

the class Uft method readAction.

/**
 * Read an action element
 * <p>
 * // * @param parentStep
 *
 * @param actionElement
 * @throws DataConversionException
 */
private TestStep readAction(Element actionElement) throws DataConversionException {
    TestStep actionStep = new TestStep("UFT: " + actionElement.getChildText("AName").trim(), Reporter.getCurrentTestResult(), new ArrayList<>(), false);
    Element summary = actionElement.getChild("Summary");
    if (summary != null && summary.getAttribute("failed").getIntValue() != 0) {
        actionStep.setFailed(true);
    }
    for (Element element : actionElement.getChildren()) {
        if ("Action".equals(element.getName())) {
            TestStep readStep = readAction(element);
            actionStep.addStep(readStep);
        } else if ("Step".equals(element.getName())) {
            TestAction readAction = readStep(element);
            actionStep.addAction(readAction);
        }
    }
    return actionStep;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Element(org.jdom2.Element) TestAction(com.seleniumtests.reporter.logger.TestAction)

Example 98 with TestStep

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

the class Uft method readXmlResult.

public List<TestStep> readXmlResult(String xmlString) {
    Document document;
    SAXBuilder builder = new SAXBuilder();
    List<TestStep> listStep = new ArrayList<>();
    try {
        String xml = xmlString.substring(xmlString.indexOf("<"));
        String xml10pattern = "[^" + "\u0009\r\n" + "\u0020-\uD7FF" + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff" + "]";
        xml = xml.replaceAll(xml10pattern, "");
        // we skip BOM by searching the first "<" character
        document = builder.build(new InputSource(new StringReader(xml)));
        Element docElement = document.getRootElement().getChild("Doc");
        Element summary = docElement.getChild("Summary");
        Element elementToIterate = docElement.getChild("DIter");
        Element iterationChild = elementToIterate.getChild("Action");
        if (!iterationChild.getChildren("Action").isEmpty()) {
            elementToIterate = iterationChild;
        }
        for (Element element : elementToIterate.getChildren()) {
            if ("Action".equals(element.getName())) {
                TestStep readStep = readAction(element);
                listStep.add(readStep);
            } else if ("Step".equals(element.getName())) {
                readStep(element);
            }
        }
    } catch (IndexOutOfBoundsException e) {
        addStepWithoutXml(listStep, "Invalid XML data: ", e);
    } catch (JDOMException | IOException e) {
        addStepWithoutXml(listStep, "Could not read UFT report: ", e);
    }
    return listStep;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) StringReader(java.io.StringReader)

Example 99 with TestStep

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

the class LogAction method commonLogTestStep.

/**
 * Log a TestStep, inside a parent TestStep or not
 * Common method used for all test step logging
 * @return
 * @throws Throwable
 */
private Object commonLogTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep) throws Throwable {
    Object reply = null;
    boolean rootStep = false;
    TestStep previousParent = null;
    // step name will contain method arguments only if it's not a configuration method (as they are generic)
    TestStep currentStep = buildRootStep(joinPoint, stepNamePrefix, !configStep);
    if ("openPage".equals(joinPoint.getSignature().getName()) && joinPoint.getTarget() instanceof PageObject) {
        PageObject page = (PageObject) joinPoint.getTarget();
        currentStep.addAction(new TestAction(String.format("Opening page %s", page.getClass().getSimpleName()), false, new ArrayList<>()));
    }
    BrowserMobProxy mobProxy = WebUIDriver.getBrowserMobProxy();
    NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver();
    VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
    // if rootStep is null, parent step is also null
    if (TestStepManager.getCurrentRootTestStep() == null) {
        // will also set parent step
        TestStepManager.setCurrentRootTestStep(currentStep);
        rootStep = true;
        if (mobProxy != null) {
            mobProxy.newPage(currentStep.getName());
        }
        if (videoRecorder != null) {
            CustomEventFiringWebDriver.displayStepOnScreen(currentStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
        }
        if (neoloadDriver != null) {
            neoloadDriver.startTransaction(currentStep.getName());
        }
    } else {
        TestStepManager.getParentTestStep().addStep(currentStep);
        previousParent = TestStepManager.getParentTestStep();
        TestStepManager.setParentTestStep(currentStep);
    }
    // set the start date once step is initialized so that when we get the video frame associated to step, step name displayed on screen is the same as the running step name
    currentStep.setStartDate();
    try {
        reply = joinPoint.proceed(joinPoint.getArgs());
    } catch (Throwable e) {
        currentStep.setFailed(true);
        currentStep.setActionException(e);
        // issue #287 (https://github.com/cbeust/testng/issues/2148): is method an @AfterMethod. Then do not rethrow exception
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        if (methodSignature.getMethod().getAnnotation(AfterMethod.class) != null) {
            scenarioLogger.error(String.format("Error in @AfterMethod %s: %s", methodSignature, e.getMessage()));
        } else {
            throw e;
        }
    } finally {
        if (rootStep) {
            TestStepManager.getCurrentRootTestStep().updateDuration();
            TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
            if (neoloadDriver != null) {
                neoloadDriver.stopTransaction();
            }
        } else {
            TestStepManager.setParentTestStep(previousParent);
        }
    }
    return reply;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) MethodSignature(org.aspectj.lang.reflect.MethodSignature) NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) ArrayList(java.util.ArrayList) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) PageObject(com.seleniumtests.uipage.PageObject) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) PageObject(com.seleniumtests.uipage.PageObject) TestAction(com.seleniumtests.reporter.logger.TestAction)

Example 100 with TestStep

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

the class SeleniumRobotTestListener method logThrowableToTestEndStep.

private void logThrowableToTestEndStep(ITestResult testResult) {
    if (testResult.getThrowable() != null) {
        logger.error(testResult.getThrowable().getMessage());
        // when error occurs, exception raised is not added to the step if this error is outside of a PageObject
        // we add it there as an exception always terminates the test (except for soft assert, but this case is handled in SoftAssertion.aj)
        TestStep lastStep = TestStepManager.getCurrentRootTestStep();
        if (lastStep == null) {
            // when steps are automatic, they are closed (lastStep is null) once method is finished
            try {
                lastStep = Iterables.getLast(SeleniumTestsContextManager.getThreadContext().getTestStepManager().getTestSteps());
            } catch (NoSuchElementException e) {
            // if last step does not exist, do not crash
            }
        }
        if (lastStep != null) {
            lastStep.setFailed(true);
            lastStep.setActionException(testResult.getThrowable());
        }
        Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
        ((MultipleInfo) lastStateInfo).addInfo(new LogInfo(testResult.getThrowable().getMessage()));
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) LogInfo(com.seleniumtests.reporter.info.LogInfo) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) Info(com.seleniumtests.reporter.info.Info) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) LogInfo(com.seleniumtests.reporter.info.LogInfo)

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