use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotServerTestRecorder method generateReport.
@Override
protected void generateReport(Map<ITestContext, Set<ITestResult>> resultSet, String outdir, boolean optimizeReport, boolean finalGeneration) {
ITestContext testCtx = SeleniumTestsContextManager.getGlobalContext().getTestNGContext();
if (testCtx == null) {
logger.error("Looks like your class does not extend from SeleniumTestPlan!");
return;
}
// issue #81: use global context because these parameters are known from there (thread context is too narrow)
if (!Boolean.TRUE.equals(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerActive()) || !SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerRecordResults() && !SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot()) {
return;
}
// check that seleniumRobot server is alive
SeleniumRobotSnapshotServerConnector serverConnector = getServerConnector();
if (!serverConnector.getActive()) {
logger.info("selenium-robot-server not found or down");
return;
} else {
try {
// create session only if it has not been before
for (ITestContext testContext : resultSet.keySet()) {
recordTestSession(testContext);
}
} catch (SeleniumRobotServerException | ConfigurationException e) {
logger.error("Error contacting selenium robot server", e);
return;
}
}
try {
recordResults(serverConnector, resultSet);
} catch (SeleniumRobotServerException | ConfigurationException e) {
logger.error("Error recording result on selenium robot server", e);
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class ErrorCauseFinder method searchMatchingInPreviousStep.
/**
* Search a test step before 'testStep' which is matching the current failed step
* e.g: we failed on step 3 so we search in 'step 2', then 'step 1' to see if one of them matches our 'step 3' visually
* @param testStepManager the TestStepManager
* @param testStep the TestStep on which we fail
* @param stepSnapshotFile the snapshot taken at the beginning of the step (which will be compared to references
* @param errorCauses the list of error causes
*/
private void searchMatchingInPreviousStep(TestStepManager testStepManager, TestStep testStep, File stepSnapshotFile, List<ErrorCause> errorCauses) {
// read the list in reverse order to find the best matching reference
List<TestStep> testStepsSubList = testStepManager.getTestSteps().subList(0, testStep.getPosition());
Collections.reverse(testStepsSubList);
for (TestStep testStep2 : testStepsSubList) {
if (testStep2.getStepResultId() != null) {
try {
File referenceSnapshot = SeleniumRobotSnapshotServerConnector.getInstance().getReferenceSnapshot(testStep2.getStepResultId());
if (referenceSnapshot == null) {
continue;
}
int matching = compareReferenceToStepSnapshot(stepSnapshotFile, referenceSnapshot);
if (matching > 80) {
errorCauses.add(new ErrorCause(ErrorType.SELENIUM_ERROR, String.format("Wrong page found, we are on the page of step '%s'", testStep2.getName()), testStep));
return;
}
} catch (ConfigurationException | SeleniumRobotServerException e) {
logger.error(e.getMessage());
}
}
}
errorCauses.add(new ErrorCause(ErrorType.UNKNOWN_PAGE, null, testStep));
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class TestNGResultUtils method changeTestResultWithSnapshotComparison.
/**
* Change the test result when snapshot comparison fails
* @param testResult
*/
public static void changeTestResultWithSnapshotComparison(final ITestResult testResult) {
if (// test is already failed
testResult.getStatus() == ITestResult.FAILURE || !Boolean.TRUE.equals(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerActive()) || // as the comparison result is only displayed, do not retry
SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.DISPLAY_ONLY || // complicated to set the test failed, and then success again
SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.ADD_TEST_RESULT || !SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot()) {
return;
}
SeleniumRobotSnapshotServerConnector serverConnector = SeleniumRobotSnapshotServerConnector.getInstance();
List<TestStep> testSteps = getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
if (testSteps == null) {
return;
}
for (TestStep testStep : testSteps) {
for (Snapshot snapshot : new ArrayList<>(testStep.getSnapshots())) {
if (snapshot.getCheckSnapshot().recordSnapshotOnServerForComparison()) {
if (snapshot.getName() == null || snapshot.getName().isEmpty()) {
logger.warn("Snapshot hasn't any name, it won't be sent to server");
continue;
}
try {
SnapshotComparisonResult comparisonResult = serverConnector.checkSnapshotHasNoDifferences(snapshot, CommonReporter.getTestCaseName(testResult), testStep.getName());
if (comparisonResult == SnapshotComparisonResult.KO) {
testResult.setStatus(ITestResult.FAILURE);
testResult.setThrowable(new ScenarioException("Snapshot comparison failed"));
// move test from passedTests to failedTests if test is not already in failed tests
if (testResult.getTestContext().getPassedTests().getAllMethods().contains(testResult.getMethod())) {
testResult.getTestContext().getPassedTests().removeResult(testResult);
testResult.getTestContext().getFailedTests().addResult(testResult, testResult.getMethod());
}
return;
}
} catch (SeleniumRobotServerException e) {
logger.error("Could not create snapshot on server", e);
}
}
}
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceErrorGettingReferenceOnServer.
/**
* We get an error when trying to get reference snapshot from server
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceErrorGettingReferenceOnServer() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
// no reference exists for stepFailed on server
when(serverConnector.getReferenceSnapshot(1)).thenThrow(new SeleniumRobotServerException("error"));
PowerMockito.whenNew(StepReferenceComparator.class).withAnyArguments().thenReturn(stepReferenceComparatorStep2);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
// no comparison done
PowerMockito.verifyNew(StepReferenceComparator.class, never()).withArguments(any(File.class), any(File.class));
Assert.assertEquals(causes.size(), 0);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Aggregations