Search in sources :

Example 1 with TestStepManager

use of com.seleniumtests.core.TestStepManager in project seleniumRobot by bhecquet.

the class ErrorCauseFinder method compareStepInErrorWithReference.

/**
 * Compare the failed step with it's reference that can be found on seleniumRobot server
 * If reference cannot be found, skip this step
 * @return
 */
public List<ErrorCause> compareStepInErrorWithReference() {
    logger.info("Searching causes: comparing with references");
    List<ErrorCause> causes = new ArrayList<>();
    // do not seearch again
    if (TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult)) {
        return causes;
    }
    // don't analyze if result has not been recorded on seleniumRobot server
    TestStepManager testStepManager = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager();
    if (testStepManager.getLastTestStep() == null || testStepManager.getLastTestStep().getStepResultId() == null) {
        return causes;
    }
    for (TestStep testStep : testStepManager.getTestSteps()) {
        // stepResultId is set when step recording is done on server
        Integer stepResultId = testStep.getStepResultId();
        if (Boolean.TRUE.equals(testStep.getFailed()) && !(testStep.getActionException() instanceof AssertionError) && stepResultId != null) {
            try {
                Snapshot stepSnapshot = testStep.getSnapshots().stream().filter(s -> s.getCheckSnapshot().recordSnapshotOnServerForReference()).collect(Collectors.toList()).get(0);
                File stepSnapshotFile = new File(stepSnapshot.getScreenshot().getFullImagePath());
                File referenceSnapshot = SeleniumRobotSnapshotServerConnector.getInstance().getReferenceSnapshot(stepResultId);
                if (referenceSnapshot == null) {
                    continue;
                }
                // perform a match between the picture of this step and the reference stored on server
                // We look at presence, position and text of each field
                List<Label> missingLabels = new ArrayList<>();
                List<Field> missingFields = new ArrayList<>();
                int matching = compareReferenceToStepSnapshot(stepSnapshotFile, referenceSnapshot, missingLabels, missingFields);
                // bad matching: the reference does not match at all the current step, we will check with other reference steps
                if (matching < 50) {
                    searchMatchingInPreviousStep(testStepManager, testStep, stepSnapshotFile, causes);
                // middle matching: we may be on the right web page but the page has changed (some fields appeared or disappeared)
                // or the text changed slightly. This could mean application changed
                } else if (matching < 90) {
                    // draw missing labels and fields
                    for (Label missingLabel : missingLabels) {
                        Rectangle rect = missingLabel.getRectangle();
                        Line2D.Double line = new Line2D.Double(rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height);
                        ImageProcessor.drawLines(referenceSnapshot, Color.RED, line);
                    }
                    ImageProcessor.drawRectangles(referenceSnapshot, Color.RED, missingFields.stream().map(Field::getRectangle).collect(Collectors.toList()).toArray(new Rectangle[] {}));
                    causes.add(new ErrorCause(ErrorType.APPLICATION_CHANGED, formatApplicationChangedDescription(missingLabels, missingFields), testStep));
                }
                break;
            } catch (IndexOutOfBoundsException e) {
            // skip this step
            } catch (Exception e) {
                logger.error(e);
            }
        }
    }
    TestNGResultUtils.setErrorCauseSearchedInReferencePicture(testResult, true);
    return causes;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TestStepManager(com.seleniumtests.core.TestStepManager) ArrayList(java.util.ArrayList) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) Rectangle(java.awt.Rectangle) Line2D(java.awt.geom.Line2D) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Snapshot(com.seleniumtests.reporter.logger.Snapshot) Field(com.seleniumtests.connectors.selenium.fielddetector.Field) File(java.io.File)

Example 2 with TestStepManager

use of com.seleniumtests.core.TestStepManager in project seleniumRobot by bhecquet.

the class TestLogActions method testVideoStartDateSetWhenVideoRecordingDisabled.

@Test(groups = { "it" })
public void testVideoStartDateSetWhenVideoRecordingDisabled() throws Exception {
    WebDriver driver = null;
    try {
        SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
        SeleniumTestsContextManager.getThreadContext().setVideoCapture("false");
        driver = WebUIDriver.getWebDriver(true);
        DriverTestPage testPage = new DriverTestPage(true);
        WaitHelper.waitForSeconds(1);
        testPage._writeSomething();
        TestStepManager stepManager = SeleniumTestsContextManager.getThreadContext().getTestStepManager();
        TestStep step = stepManager.getTestSteps().get(2);
        Assert.assertEquals(step.getVideoTimeStamp(), 0);
        Assert.assertNull(stepManager.getVideoStartDate());
    } finally {
        if (driver != null) {
            WebUIDriver.cleanUp();
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) TestStep(com.seleniumtests.reporter.logger.TestStep) DriverTestPage(com.seleniumtests.it.driver.support.pages.DriverTestPage) TestStepManager(com.seleniumtests.core.TestStepManager) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 3 with TestStepManager

use of com.seleniumtests.core.TestStepManager in project seleniumRobot by bhecquet.

the class TestLogActions method testVideoStartDateSetWhenVideoRecordingEnabled.

@Test(groups = { "it" })
public void testVideoStartDateSetWhenVideoRecordingEnabled() throws Exception {
    WebDriver driver = null;
    try {
        SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
        SeleniumTestsContextManager.getThreadContext().setVideoCapture("true");
        driver = WebUIDriver.getWebDriver(true);
        DriverTestPage testPage = new DriverTestPage(true);
        WaitHelper.waitForSeconds(1);
        testPage._writeSomething();
        TestStepManager stepManager = SeleniumTestsContextManager.getThreadContext().getTestStepManager();
        TestStep step = stepManager.getTestSteps().get(2);
        Assert.assertTrue(step.getVideoTimeStamp() > 0);
        Assert.assertNotNull(stepManager.getVideoStartDate());
    } finally {
        if (driver != null) {
            WebUIDriver.cleanUp();
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) TestStep(com.seleniumtests.reporter.logger.TestStep) DriverTestPage(com.seleniumtests.it.driver.support.pages.DriverTestPage) TestStepManager(com.seleniumtests.core.TestStepManager) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

TestStepManager (com.seleniumtests.core.TestStepManager)3 TestStep (com.seleniumtests.reporter.logger.TestStep)3 GenericTest (com.seleniumtests.GenericTest)2 DriverTestPage (com.seleniumtests.it.driver.support.pages.DriverTestPage)2 WebDriver (org.openqa.selenium.WebDriver)2 Test (org.testng.annotations.Test)2 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)1 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1 Snapshot (com.seleniumtests.reporter.logger.Snapshot)1 Rectangle (java.awt.Rectangle)1 Line2D (java.awt.geom.Line2D)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1