use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceNoReferenceSnapshot.
/**
* Failed test step does not contain a "reference snapshot" so there is no way to compare it to the one stored on server
* No error should be raised
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceNoReferenceSnapshot() throws Exception {
stepFailed.getSnapshots().removeAll(stepFailed.getSnapshots());
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.ErrorCause in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceMediumMatch2.
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceMediumMatch2() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
// comparison successful
PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep2).thenReturn(stepReferenceComparatorStep2);
when(stepReferenceComparatorStep2.compare()).thenReturn(50);
when(stepReferenceComparatorStep2.getMissingLabels()).thenReturn(Arrays.asList(new Label(0, 100, 20, 50, "some label")));
List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
Assert.assertEquals(causes.size(), 1);
Assert.assertEquals(causes.get(0).getType(), ErrorType.APPLICATION_CHANGED);
Assert.assertEquals(causes.get(0).getDescription(), "1 Label(s) missing: \n" + "some label\n");
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
// check line has been drawn below the missing label
BufferedImage image = ImageIO.read(referenceImgStep2);
Assert.assertEquals(new Color(image.getRGB(0, 50)), Color.RED);
Assert.assertNotEquals(new Color(image.getRGB(0, 20)), Color.RED);
Assert.assertEquals(new Color(image.getRGB(100, 50)), Color.RED);
Assert.assertNotEquals(new Color(image.getRGB(100, 20)), Color.RED);
}
use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceGoodMatch.
// bad match => pas de step avant celle qui plante
/**
* Matching between reference picture stored on server and the one for current test is very good (we are on the right page)
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceGoodMatch() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
// comparison successful
PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep2).thenReturn(stepReferenceComparatorStep2);
when(stepReferenceComparatorStep2.compare()).thenReturn(90);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
Assert.assertEquals(causes.size(), 0);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepErrorMessageWithFailedStep.
/**
* When a failed step is present, attach ErrorCause to this one instead of "Last Step"
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessageWithFailedStep() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, 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);
Assert.assertEquals(causes.get(0).getDescription(), "il y a eu un gros problème");
// error cause is associated to the last failed step
Assert.assertEquals(causes.get(0).getTestStep(), stepFailed);
Assert.assertEquals(causes.get(1).getType(), ErrorType.ERROR_MESSAGE);
Assert.assertEquals(causes.get(1).getDescription(), "some error");
// error cause is associated to the last failed step
Assert.assertEquals(causes.get(1).getTestStep(), stepFailed);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepAlreadyDone.
@Test(groups = { "ut" })
public void testSearchInLastStepAlreadyDone() 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);
TestNGResultUtils.setErrorCauseSearchedInLastStep(testResult, true);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
Assert.assertEquals(causes.size(), 0);
}
Aggregations