Search in sources :

Example 21 with Label

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);
}
Also used : JSONObject(kong.unirest.json.JSONObject) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 22 with Label

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));
}
Also used : Label(com.seleniumtests.connectors.selenium.fielddetector.Label) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 23 with Label

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));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Label(com.seleniumtests.connectors.selenium.fielddetector.Label)

Example 24 with Label

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));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 25 with Label

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));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

Label (com.seleniumtests.connectors.selenium.fielddetector.Label)37 Test (org.testng.annotations.Test)31 GenericTest (com.seleniumtests.GenericTest)26 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)22 File (java.io.File)14 MockitoTest (com.seleniumtests.MockitoTest)13 JSONObject (kong.unirest.json.JSONObject)13 ArrayList (java.util.ArrayList)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)8 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)8 ITestResult (org.testng.ITestResult)8 ImageFieldDetector (com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector)6 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)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 Rectangle (java.awt.Rectangle)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1