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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations