use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceMediumMatch.
/**
* Matching between reference picture stored on server and the one for current test is good enough (we are on the right page but something changed)
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceMediumMatch() 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.getMissingFields()).thenReturn(Arrays.asList(new Field(0, 100, 0, 20, "", "field")));
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 field(s) missing: \n" + "field[text=]: java.awt.Rectangle[x=0,y=0,width=100,height=20]\n");
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
// check rectangle has been drawn around the missing field
BufferedImage image = ImageIO.read(referenceImgStep2);
Assert.assertEquals(new Color(image.getRGB(0, 20)), Color.RED);
Assert.assertEquals(new Color(image.getRGB(0, 0)), Color.RED);
Assert.assertEquals(new Color(image.getRGB(100, 20)), Color.RED);
Assert.assertEquals(new Color(image.getRGB(100, 0)), Color.RED);
}
use of com.seleniumtests.core.testanalysis.ErrorCauseFinder in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceNoReferenceOnServer.
/**
* There is no reference for this step on server
* Search is considered as done
* @throws Exception
*/
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceNoReferenceOnServer() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
// no reference exists for stepFailed on server
when(serverConnector.getReferenceSnapshot(1)).thenReturn(null);
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 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.ErrorCauseFinder 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.ErrorCauseFinder 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));
}
Aggregations