use of com.seleniumtests.connectors.selenium.fielddetector.Label in project seleniumRobot by bhecquet.
the class TestLabel method testFromJsonNoText.
/**
* Test case where text key is not present
*/
@Test(groups = { "ut" })
public void testFromJsonNoText() {
Label label = Label.fromJson(new JSONObject("{" + " \"top\": 2261," + " \"left\": 8," + " \"width\": 96," + " \"height\": 14," + " \"right\": 104," + " \"bottom\": 2275" + " }"));
Assert.assertEquals(label.getText(), null);
}
use of com.seleniumtests.connectors.selenium.fielddetector.Label in project seleniumRobot by bhecquet.
the class TestLabel method testMatchesNullText3.
/**
* If both texts are null, only rely on position
*/
@Test(groups = { "ut" })
public void testMatchesNullText3() {
Label l1 = new Label(0, 100, 0, 20, null);
Label l2 = new Label(0, 99, 0, 20, null);
Assert.assertTrue(l1.match(l2));
}
use of com.seleniumtests.connectors.selenium.fielddetector.Label 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.Label in project seleniumRobot by bhecquet.
the class TestLabel method testIsNotInsideLeft.
/**
* Label is on the left of field
* ----- ------
* Label Field
* ----- ------
*/
@Test(groups = { "ut" })
public void testIsNotInsideLeft() {
Label label = Label.fromJson(new JSONObject("{" + " \"top\": 674," + " \"left\": 50," + " \"width\": 100," + " \"height\": 20," + " \"text\": \"My link Parent\"," + " \"right\": 150," + " \"bottom\": 694" + " }"));
Field field = Field.fromJson(new JSONObject("{" + " \"class_id\": 3," + " \"top\": 674," + " \"bottom\": 694," + " \"left\": 100," + " \"right\": 200," + " \"class_name\": \"radio_with_label\"," + " \"text\": \"= Value 4\"," + " \"related_field\": null," + " \"with_label\": true," + " \"width\": 100," + " \"height\": 20" + " }"));
Assert.assertFalse(label.isInside(field));
Assert.assertFalse(label.isFieldLeftOf(field));
Assert.assertTrue(label.isFieldRightOf(field));
Assert.assertFalse(label.isFieldAbove(field));
Assert.assertFalse(label.isFieldBelow(field));
}
use of com.seleniumtests.connectors.selenium.fielddetector.Label in project seleniumRobot by bhecquet.
the class TestLabel method testIsNotInsideAbove.
/**
* Label is on the top of field
*
* ------
* Label
* ------
*
* -----
* Field
* -----
*/
@Test(groups = { "ut" })
public void testIsNotInsideAbove() {
Label label = Label.fromJson(new JSONObject("{" + " \"top\": 664," + " \"left\": 20," + " \"width\": 121," + " \"height\": 22," + " \"text\": \"My link Parent\"," + " \"right\": 141," + " \"bottom\": 684" + " }"));
Field field = Field.fromJson(new JSONObject("{" + " \"class_id\": 3," + " \"top\": 674," + " \"bottom\": 694," + " \"left\": 20," + " \"right\": 141," + " \"class_name\": \"radio_with_label\"," + " \"text\": \"= Value 4\"," + " \"related_field\": null," + " \"with_label\": true," + " \"width\": 121," + " \"height\": 22" + " }"));
Assert.assertFalse(label.isInside(field));
Assert.assertFalse(label.isFieldLeftOf(field));
Assert.assertFalse(label.isFieldRightOf(field));
Assert.assertFalse(label.isFieldAbove(field));
Assert.assertTrue(label.isFieldBelow(field));
}
Aggregations