Search in sources :

Example 16 with SeleniumRobotServerException

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);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ITestContext(org.testng.ITestContext) SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 17 with SeleniumRobotServerException

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));
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 18 with SeleniumRobotServerException

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);
                }
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ArrayList(java.util.ArrayList) SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 19 with SeleniumRobotServerException

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));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)19 UnirestException (kong.unirest.UnirestException)14 JSONException (kong.unirest.json.JSONException)11 JSONObject (kong.unirest.json.JSONObject)9 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 File (java.io.File)7 ArrayList (java.util.ArrayList)4 TestStep (com.seleniumtests.reporter.logger.TestStep)3 SeleniumRobotSnapshotServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector)2 BrowserType (com.seleniumtests.driver.BrowserType)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 IOException (java.io.IOException)2 GetRequest (kong.unirest.GetRequest)2 JSONArray (kong.unirest.json.JSONArray)2 GenericTest (com.seleniumtests.GenericTest)1 MockitoTest (com.seleniumtests.MockitoTest)1 SnapshotComparisonResult (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult)1 TestVariable (com.seleniumtests.core.TestVariable)1 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)1 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)1