use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class WebUIDriver method createRemoteWebDriver.
/**
* prepare driver:
* - create it
* - add listeners
* - create and start video capture
* - create and start network capture proxy
* - record driver and browser pid so that they can be deleted at the end of test session
* @return
*/
public WebDriver createRemoteWebDriver() {
webDriverBuilder = getWebDriverBuilderFactory();
logger.info("driver mode: " + config.getMode());
synchronized (createDriverLock) {
// get browser info used to start this driver. It will be used then for managing pids
BrowserInfo browserInfo = webDriverBuilder.getSelectedBrowserInfo();
List<Long> existingPids = new ArrayList<>();
// get pid pre-existing the creation of this driver. This helps filtering drivers launched by other tests or users
if (browserInfo != null) {
existingPids.addAll(browserInfo.getDriverAndBrowserPid(new ArrayList<>()));
}
TestStep cuurrentTestStep = TestStepManager.getCurrentRootTestStep();
long start = new Date().getTime();
long duration;
try {
driver = webDriverBuilder.createWebDriver();
} finally {
duration = new Date().getTime() - start;
if (cuurrentTestStep != null) {
cuurrentTestStep.setDurationToExclude(duration);
}
scenarioLogger.info(String.format("driver creation took: %.1f secs", duration / 1000.0));
}
WaitHelper.waitForSeconds(2);
List<Long> driverPids = new ArrayList<>();
// get the created PIDs
if (browserInfo != null) {
driverPids = browserInfo.getDriverAndBrowserPid(existingPids);
}
// issue #280: we use 'webDriverBuilder.getSelectedBrowserInfo()' as 'browserInfo' variable is null for grid, whereas, 'webDriverBuilder.getSelectedBrowserInfo()'
// gets an updated version once the driver has been created on grid
driver = handleListeners(driver, webDriverBuilder.getSelectedBrowserInfo(), driverPids);
if (driver != null) {
MutableCapabilities caps = ((CustomEventFiringWebDriver) driver).getInternalCapabilities();
caps.setCapability(DriverUsage.STARTUP_DURATION, duration);
caps.setCapability(DriverUsage.START_TIME, start);
// capability from IDestkopCapabilitiesFactory is not available when we request capabilities from driver.
if (config.getTestContext() != null && config.getTestContext().getTestNGResult() != null) {
String testName = TestNGResultUtils.getTestName(config.getTestContext().getTestNGResult());
caps.setCapability(DriverUsage.TEST_NAME, testName);
}
}
if (config.getBrowserMobProxy() != null) {
config.getBrowserMobProxy().newHar(SeleniumTestsContextManager.getThreadContext().getRelativeOutputDir());
}
if (config.getVideoCapture() != VideoCaptureMode.FALSE && videoRecorder.get() == null) {
try {
VideoRecorder recorder = CustomEventFiringWebDriver.startVideoCapture(SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()), "videoCapture.avi");
videoRecorder.set(recorder);
TestStepManager.setVideoStartDate();
} catch (ScenarioException e) {
logger.warn("Video capture won't start: " + e.getMessage());
}
}
}
return driver;
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class TestStepManager method logTestStep.
/**
* Logs the testStep for this test
* Once logging is done, parentTestStep and currentRootTestStep are reset to avoid storing new data in them
* @param testStep
* @param storeStep
*/
public static void logTestStep(TestStep testStep, boolean storeStep) {
List<TestAction> actionList = testStep.getStepActions();
if (!actionList.isEmpty()) {
for (TestAction action : actionList) {
if (action instanceof TestStep) {
logTestStep((TestStep) action, false);
}
}
}
if (storeStep) {
// notify each TestStepManager about the new test step (useful for AfterClass / AfterTest configuration methods)
for (SeleniumTestsContext testContext : SeleniumTestsContextManager.getContextForCurrentTestState()) {
TestStepManager stepManager = testContext.getTestStepManager();
stepManager.getTestSteps().add(testStep);
stepManager.setRootTestStep(null);
stepManager.setRunningTestStep(null);
}
}
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class TestTasks method terminateCurrentStep.
public static void terminateCurrentStep() {
NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver();
// log the previous step if it exists and create the new one
TestStep previousStep = TestStepManager.getCurrentRootTestStep();
if (previousStep != null) {
previousStep.updateDuration();
TestStepManager.logTestStep(previousStep);
if (neoloadDriver != null) {
neoloadDriver.stopTransaction();
}
}
}
use of com.seleniumtests.reporter.logger.TestStep 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.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class ErrorCauseFinder method findErrorInLastStepSnapshots.
/**
* Search in snapshots of the last step if there are any displayed errors (error messages or fields in error)
* @return
*/
public List<ErrorCause> findErrorInLastStepSnapshots() {
logger.info("Searching causes: find errors in last snapshot");
List<ErrorCause> causes = new ArrayList<>();
// do not seearch again
if (TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult)) {
return causes;
}
TestStep lastTestStep = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getLastTestStep();
TestStep lastFailedStep = lastTestStep;
for (TestStep testStep : TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps()) {
if (Boolean.TRUE.equals(testStep.getFailed()) && testStep != lastTestStep) {
lastFailedStep = testStep;
}
}
if (lastTestStep != null) {
for (Snapshot snapshot : lastTestStep.getSnapshots()) {
try {
ImageFieldDetector imageFieldDetector = new ImageFieldDetector(new File(snapshot.getScreenshot().getFullImagePath()), 1, FieldType.ERROR_MESSAGES_AND_FIELDS);
List<Field> fields = imageFieldDetector.detectFields();
List<Label> labels = imageFieldDetector.detectLabels();
// are some text considered as error messages (mainly in red on page)
parseFields(causes, fields, labels, lastFailedStep);
// do some label contain "error" or "problem"
parseLabels(causes, labels, lastFailedStep);
} catch (Exception e) {
logger.error("Error searching for errors in last snapshots: " + e.getMessage());
break;
}
}
TestNGResultUtils.setErrorCauseSearchedInLastStep(testResult, true);
}
return causes;
}
Aggregations