Search in sources :

Example 1 with SnapshotComparisonResult

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult in project seleniumRobot by bhecquet.

the class TestSeleniumRobotSnapshotServerConnector method testCheckSnapshotHasNoDifferencesWithComputingError.

@Test(groups = { "ut" })
public void testCheckSnapshotHasNoDifferencesWithComputingError() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    // set it directly has it has been reset on creation
    connector.setVersionId(11);
    createServerMock("PUT", SeleniumRobotSnapshotServerConnector.SNAPSHOT_API_URL, 200, "{'id': null, 'computed': true, 'computingError': 'Error computing', 'diffPixelPercentage': 0.0, 'tooManyDiffs': false}");
    SnapshotComparisonResult snapshotHasNoDifference = connector.checkSnapshotHasNoDifferences(snapshot, "Test 1", "Step 1");
    // In case of computing errors, it may be due to server problem, so do not retry
    Assert.assertEquals(snapshotHasNoDifference, SnapshotComparisonResult.NOT_DONE);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with SnapshotComparisonResult

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult in project seleniumRobot by bhecquet.

the class TestSeleniumRobotSnapshotServerConnector method testCheckSnapshotHasNoDifferencesWithDiff.

@Test(groups = { "ut" })
public void testCheckSnapshotHasNoDifferencesWithDiff() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    // set it directly has it has been reset on creation
    connector.setVersionId(11);
    createServerMock("PUT", SeleniumRobotSnapshotServerConnector.SNAPSHOT_API_URL, 200, "{'id': null, 'computed': true, 'computingError': '', 'diffPixelPercentage': 10.0, 'tooManyDiffs': true}");
    SnapshotComparisonResult snapshotHasNoDifference = connector.checkSnapshotHasNoDifferences(snapshot, "Test 1", "Step 1");
    // When there are differences, return false
    Assert.assertEquals(snapshotHasNoDifference, SnapshotComparisonResult.KO);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with SnapshotComparisonResult

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult 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 4 with SnapshotComparisonResult

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult in project seleniumRobot by bhecquet.

the class TestSeleniumRobotSnapshotServerConnector method testCheckSnapshotHasNoDifferences.

@Test(groups = { "ut" })
public void testCheckSnapshotHasNoDifferences() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    // set it directly has it has been reset on creation
    connector.setVersionId(11);
    SnapshotComparisonResult snapshotHasNoDifference = connector.checkSnapshotHasNoDifferences(snapshot, "Test 1", "Step 1");
    // When no difference is found, return true
    Assert.assertEquals(snapshotHasNoDifference, SnapshotComparisonResult.OK);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with SnapshotComparisonResult

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult in project seleniumRobot by bhecquet.

the class TestSeleniumRobotSnapshotServerConnector method testCheckSnapshotHasNoDifferencesWithOutdatedServer.

/**
 * Check the case were seleniumRobot server is not up to date and createSnapshot API only returns id
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testCheckSnapshotHasNoDifferencesWithOutdatedServer() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    // set it directly has it has been reset on creation
    connector.setVersionId(11);
    createServerMock("PUT", SeleniumRobotSnapshotServerConnector.SNAPSHOT_API_URL, 200, "{'id': '16'}");
    SnapshotComparisonResult snapshotHasNoDifference = connector.checkSnapshotHasNoDifferences(snapshot, "Test 1", "Step 1");
    // In case API is not up to date, checkSnapshotHasNoDifferences returns 'NOT_DONE'
    Assert.assertEquals(snapshotHasNoDifference, SnapshotComparisonResult.NOT_DONE);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SeleniumRobotSnapshotServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector)6 SnapshotComparisonResult (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult)6 ConnectorsTest (com.seleniumtests.ConnectorsTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1 Snapshot (com.seleniumtests.reporter.logger.Snapshot)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 ArrayList (java.util.ArrayList)1