Search in sources :

Example 6 with ErrorCauseFinder

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);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Color(java.awt.Color) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 7 with ErrorCauseFinder

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));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 8 with ErrorCauseFinder

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));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 9 with ErrorCauseFinder

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);
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Color(java.awt.Color) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 10 with ErrorCauseFinder

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));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)28 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)28 ITestResult (org.testng.ITestResult)28 GenericTest (com.seleniumtests.GenericTest)27 MockitoTest (com.seleniumtests.MockitoTest)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Test (org.testng.annotations.Test)27 File (java.io.File)25 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)8 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)8 StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)8 ArrayList (java.util.ArrayList)7 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1