Search in sources :

Example 21 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class UiElement method findElementByPosition.

private void findElementByPosition() {
    // search the fields with label
    Label labelRightOf = null;
    Label labelLeftOf = null;
    Label labelAbove = null;
    Label labelBelow = null;
    Label labelText = null;
    if (by.getRightOf() != null) {
        for (Label lbl : labelsPerPage.get(origin)) {
            if (by.getRightOf().matcher(lbl.getText().trim()).matches()) {
                labelRightOf = lbl;
                break;
            }
        }
    }
    if (by.getLeftOf() != null) {
        for (Label lbl : labelsPerPage.get(origin)) {
            if (by.getLeftOf().matcher(lbl.getText().trim()).matches()) {
                labelLeftOf = lbl;
                break;
            }
        }
    }
    if (by.getAbove() != null) {
        for (Label lbl : labelsPerPage.get(origin)) {
            if (by.getAbove().matcher(lbl.getText().trim()).matches()) {
                labelAbove = lbl;
                break;
            }
        }
    }
    if (by.getBelow() != null) {
        for (Label lbl : labelsPerPage.get(origin)) {
            if (by.getBelow().matcher(lbl.getText().trim()).matches()) {
                labelBelow = lbl;
                break;
            }
        }
    }
    if (by.getText() != null) {
        for (Label lbl : labelsPerPage.get(origin)) {
            if (by.getText().matcher(lbl.getText().trim()).matches()) {
                labelText = lbl;
                break;
            }
        }
    }
    if (labelLeftOf == null && labelRightOf == null && labelText == null && labelAbove == null && labelBelow == null) {
        throw new ConfigurationException(String.format("No label could be found matching search criteria [%s]", by));
    }
    for (Field field : fieldsPerPage.get(origin)) {
        if (ElementType.fromClassName(field.getClassName()) == elementType && // only use raw fields
        field.getRelatedField() == null && (labelText == null || labelText.isInside(field)) && (labelRightOf == null || labelRightOf.isFieldRightOf(field)) && (labelLeftOf == null || labelLeftOf.isFieldLeftOf(field)) && (labelAbove == null || labelAbove.isFieldAbove(field)) && (labelBelow == null || labelBelow.isFieldBelow(field))) {
            detectedObjectRectangle = field.getRectangle();
            return;
        }
    }
    throw new ConfigurationException(String.format("No field could be found matching search criteria [%s]", by));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Label(com.seleniumtests.connectors.selenium.fielddetector.Label)

Example 22 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestField method testNoMatcheNullClass.

@Test(groups = { "ut" })
public void testNoMatcheNullClass() {
    Field f1 = new Field(0, 100, 0, 20, "foobar", null);
    Field f2 = new Field(0, 99, 0, 20, "fooba", null);
    Assert.assertFalse(f1.match(f2));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 23 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestField method testFromJson.

@Test(groups = { "ut" })
public void testFromJson() {
    Field field = Field.fromJson(new JSONObject("{" + "		\"top\": 2261," + "		\"left\": 8," + "		\"width\": 96," + "		\"height\": 14," + "		\"class_name\": \"radio_with_label\"," + "		\"class_id\": 3," + "		\"text\": \"= Value 4\"," + "		\"related_field\": null," + "		\"with_label\": true," + "		\"right\": 104," + "		\"bottom\": 2275" + "	}"));
    Assert.assertEquals(field.getLabel().getLeft(), 8);
    Assert.assertEquals(field.getLabel().getRight(), 104);
    Assert.assertEquals(field.getLabel().getTop(), 2261);
    Assert.assertEquals(field.getLabel().getBottom(), 2275);
    Assert.assertEquals(field.getLabel().getHeight(), 14);
    Assert.assertEquals(field.getLabel().getWidth(), 96);
    Assert.assertEquals(field.getRectangle(), new Rectangle(8, 2261, 96, 14));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) Rectangle(java.awt.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 24 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestField method testNoMatcheClass.

@Test(groups = { "ut" })
public void testNoMatcheClass() {
    Field f1 = new Field(0, 100, 0, 20, "foobar", "radio");
    Field f2 = new Field(0, 99, 0, 20, "fooba", "field");
    Assert.assertFalse(f1.match(f2));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 25 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestImageFieldDetector method testDetectFields.

@Test(groups = { "ut" })
public void testDetectFields() throws IOException {
    JSONObject obj = new JSONObject("{" + "	\"fields\": [{" + "		\"class_id\": 3," + "		\"top\": 674," + "		\"bottom\": 696," + "		\"left\": 20," + "		\"right\": 141," + "		\"class_name\": \"radio_with_label\"," + "		\"text\": \"= Value 4\"," + "		\"related_field\": null," + "		\"with_label\": true," + "		\"width\": 121," + "		\"height\": 22" + "	}," + "	{" + "		\"class_id\": 3," + "		\"top\": 975," + "		\"bottom\": 996," + "		\"left\": 4," + "		\"right\": 90," + "		\"class_name\": \"radio_with_label\"," + "		\"text\": \"an other text\"," + "		\"related_field\": null," + "		\"with_label\": true," + "		\"width\": 86," + "		\"height\": 21" + "	}]," + "	\"labels\": [{" + "		\"top\": 24," + "		\"left\": 8," + "		\"width\": 244," + "		\"height\": 16," + "		\"text\": \"Test clicking a moving element\"," + "		\"right\": 252," + "		\"bottom\": 40" + "	}," + "	{" + "		\"top\": 63," + "		\"left\": 16," + "		\"width\": 89," + "		\"height\": 11," + "		\"text\": \"Start Animation\"," + "		\"right\": 105," + "		\"bottom\": 74" + "	}]" + "} ");
    File image = createImageFromResource("ti/form_picture.png");
    when(fieldDetectorConnector.detect(image, 1)).thenReturn(obj);
    SeleniumTestsContextManager.getGlobalContext().setFieldDetectorInstance(fieldDetectorConnector);
    List<Field> fields = new ImageFieldDetector(image).detectFields();
    Assert.assertEquals(fields.size(), 2);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) ImageFieldDetector(com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector) File(java.io.File) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

Field (com.seleniumtests.connectors.selenium.fielddetector.Field)35 Test (org.testng.annotations.Test)29 GenericTest (com.seleniumtests.GenericTest)23 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)22 File (java.io.File)17 MockitoTest (com.seleniumtests.MockitoTest)14 JSONObject (kong.unirest.json.JSONObject)14 ArrayList (java.util.ArrayList)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 ImageFieldDetector (com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector)9 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)8 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)8 ITestResult (org.testng.ITestResult)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)5 Rectangle (java.awt.Rectangle)4 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1