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