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