use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepDetectedErrorMessage.
/**
* An error_message field is found. We try to relate it to a label
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepDetectedErrorMessage() 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, 0, 20, "ko"));
labels.add(new Label(0, 100, 100, 120, "nothing"));
List<Field> fields = new ArrayList<>();
fields.add(new Field(0, 100, 0, 20, "", ErrorCauseFinder.CLASS_ERROR_MESSAGE));
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(), 1);
Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_MESSAGE);
Assert.assertEquals(causes.get(0).getDescription(), "ko");
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepNoErrors.
/**
* no error message in the page, no cause should be found
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepNoErrors() 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, "tout roule"));
labels.add(new Label(0, 100, 100, 120, "everything is fine"));
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(), 0);
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceErrorInComparison.
/**
* If any error occurs in comparison, continue
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceErrorInComparison() 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()).thenThrow(new ConfigurationException("error on init"));
List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
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 testSearchInLastStepDetectedErrorField.
/**
* In case an error_field is found, check we show it as an error
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepDetectedErrorField() 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, "ok"));
labels.add(new Label(0, 100, 100, 120, "nothing"));
List<Field> fields = new ArrayList<>();
fields.add(new Field(0, 100, 0, 20, "", ErrorCauseFinder.CLASS_ERROR_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(), 1);
Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_IN_FIELD);
Assert.assertEquals(causes.get(0).getDescription(), "At least one field in error");
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepErrorMessageWithException.
/**
* Check error is only logged when something goes wrong while analyzing picture
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessageWithException() 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()).thenThrow(new ConfigurationException("error"));
when(imageFieldDetector.detectLabels()).thenReturn(labels);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
Assert.assertEquals(causes.size(), 0);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Aggregations