use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceAssertionError.
/**
* When step fails due to assertion error, we do not compare snapshot with reference as the failure is expected
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceAssertionError() throws Exception {
stepFailed.setActionException(new AssertionError("result is not the expected one"));
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
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));
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepErrorMessage.
/**
* Check error causes are found with various error messages
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessage() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
List<Label> labels = new ArrayList<>();
labels.add(new Label(0, 100, 20, 50, "il y a eu un gros problème"));
labels.add(new Label(0, 100, 100, 120, "some error"));
List<Field> fields = new ArrayList<>();
fields.add(new Field(0, 100, 0, 20, "", "field"));
fields.add(new Field(0, 100, 200, 220, "", "field"));
when(imageFieldDetector.detectFields()).thenReturn(fields);
when(imageFieldDetector.detectLabels()).thenReturn(labels);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
Assert.assertEquals(causes.size(), 2);
Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_MESSAGE);
// no failed step except "last step", keep association
Assert.assertEquals(causes.get(0).getTestStep(), lastStep);
Assert.assertEquals(causes.get(0).getDescription(), "il y a eu un gros problème");
Assert.assertEquals(causes.get(1).getType(), ErrorType.ERROR_MESSAGE);
Assert.assertEquals(causes.get(1).getDescription(), "some error");
Assert.assertEquals(causes.get(1).getTestStep(), lastStep);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceNoIDForStep2.
/**
* Same thing as above but only the failed step has no ID
* In this case, we consider comparison has been performed because other steps have IDs
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceNoIDForStep2() throws Exception {
stepFailed.setStepResultId(null);
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
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