Search in sources :

Example 1 with StepReferenceComparator

use of com.seleniumtests.util.imaging.StepReferenceComparator in project seleniumRobot by bhecquet.

the class ErrorCauseFinder method compareReferenceToStepSnapshot.

private int compareReferenceToStepSnapshot(File stepSnapshot, File referenceSnapshot, List<Label> missingLabels, List<Field> missingFields) {
    StepReferenceComparator stepReferenceComparator = new StepReferenceComparator(stepSnapshot, referenceSnapshot);
    int matching = stepReferenceComparator.compare();
    missingLabels.addAll(stepReferenceComparator.getMissingLabels());
    missingFields.addAll(stepReferenceComparator.getMissingFields());
    return matching;
}
Also used : StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator)

Example 2 with StepReferenceComparator

use of com.seleniumtests.util.imaging.StepReferenceComparator in project seleniumRobot by bhecquet.

the class TestStepReferenceComparator method testCompareNoFieldNoLabel.

@Test(groups = { "ut" })
public void testCompareNoFieldNoLabel() throws Exception {
    PowerMockito.whenNew(ImageFieldDetector.class).withAnyArguments().thenReturn(stepImageFieldDetector, refImageFieldDetector);
    StepReferenceComparator comparator = new StepReferenceComparator(File.createTempFile("img", ".png"), File.createTempFile("img", ".png"));
    Assert.assertEquals(comparator.compare(), 100);
}
Also used : StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with StepReferenceComparator

use of com.seleniumtests.util.imaging.StepReferenceComparator in project seleniumRobot by bhecquet.

the class TestStepReferenceComparator method testComparePartialMatch.

@Test(groups = { "ut" })
public void testComparePartialMatch() throws Exception {
    List<Label> stepLabels = new ArrayList<>();
    stepLabels.add(new Label(0, 100, 20, 50, "a text"));
    stepLabels.add(new Label(0, 100, 100, 120, "other text"));
    List<Label> referenceLabels = new ArrayList<>();
    referenceLabels.add(new Label(0, 100, 0, 20, "a text"));
    referenceLabels.add(new Label(5, 105, 100, 120, "other text"));
    List<Field> stepFields = new ArrayList<>();
    stepFields.add(new Field(0, 100, 0, 20, "", "field"));
    stepFields.add(new Field(0, 100, 200, 220, "", "field"));
    List<Field> referenceFields = new ArrayList<>();
    referenceFields.add(new Field(0, 100, 0, 20, "", "field"));
    referenceFields.add(new Field(5, 105, 100, 120, "", "field"));
    PowerMockito.whenNew(ImageFieldDetector.class).withAnyArguments().thenReturn(stepImageFieldDetector, refImageFieldDetector);
    when(stepImageFieldDetector.detectLabels()).thenReturn(stepLabels);
    when(refImageFieldDetector.detectLabels()).thenReturn(referenceLabels);
    when(stepImageFieldDetector.detectFields()).thenReturn(stepFields);
    when(refImageFieldDetector.detectFields()).thenReturn(referenceFields);
    StepReferenceComparator comparator = new StepReferenceComparator(File.createTempFile("img", ".png"), File.createTempFile("img", ".png"));
    Assert.assertEquals(comparator.compare(), 50);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with StepReferenceComparator

use of com.seleniumtests.util.imaging.StepReferenceComparator in project seleniumRobot by bhecquet.

the class TestStepReferenceComparator method testCompareNoLabel.

/**
 * List of fields are the same, comparison is successful (no labels)
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareNoLabel() throws Exception {
    List<Field> stepFields = new ArrayList<>();
    stepFields.add(new Field(0, 100, 0, 20, "", "field"));
    stepFields.add(new Field(0, 100, 100, 120, "", "field"));
    List<Field> referenceFields = new ArrayList<>();
    referenceFields.add(new Field(0, 100, 0, 20, "", "field"));
    referenceFields.add(new Field(5, 105, 100, 120, "", "field"));
    PowerMockito.whenNew(ImageFieldDetector.class).withAnyArguments().thenReturn(stepImageFieldDetector, refImageFieldDetector);
    when(stepImageFieldDetector.detectFields()).thenReturn(stepFields);
    when(refImageFieldDetector.detectFields()).thenReturn(referenceFields);
    StepReferenceComparator comparator = new StepReferenceComparator(File.createTempFile("img", ".png"), File.createTempFile("img", ".png"));
    int matching = comparator.compare();
    Assert.assertEquals(matching, 100);
    PowerMockito.verifyNew(ImageFieldDetector.class, times(2)).withArguments(any(File.class), anyDouble(), eq(FieldType.ALL_FORM_FIELDS));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ImageFieldDetector(com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector) ArrayList(java.util.ArrayList) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) File(java.io.File) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with StepReferenceComparator

use of com.seleniumtests.util.imaging.StepReferenceComparator in project seleniumRobot by bhecquet.

the class TestStepReferenceComparator method testCompareNoField.

@Test(groups = { "ut" })
public void testCompareNoField() throws Exception {
    List<Label> stepLabels = new ArrayList<>();
    stepLabels.add(new Label(0, 100, 0, 20, "a text"));
    stepLabels.add(new Label(0, 100, 100, 120, "other text"));
    List<Label> referenceLabels = new ArrayList<>();
    referenceLabels.add(new Label(0, 100, 0, 20, "a text"));
    referenceLabels.add(new Label(5, 105, 100, 120, "other text"));
    PowerMockito.whenNew(ImageFieldDetector.class).withAnyArguments().thenReturn(stepImageFieldDetector, refImageFieldDetector);
    when(stepImageFieldDetector.detectLabels()).thenReturn(stepLabels);
    when(refImageFieldDetector.detectLabels()).thenReturn(referenceLabels);
    StepReferenceComparator comparator = new StepReferenceComparator(File.createTempFile("img", ".png"), File.createTempFile("img", ".png"));
    Assert.assertEquals(comparator.compare(), 100);
}
Also used : Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)5 MockitoTest (com.seleniumtests.MockitoTest)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)3 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)2 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)2 ImageFieldDetector (com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector)1 File (java.io.File)1