Search in sources :

Example 11 with Field

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

the class TestField method testMatches.

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

Example 12 with Field

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

the class TestField method testChangePosition.

@Test(groups = { "ut" })
public void testChangePosition() {
    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" + "	}"));
    field.changePosition(10, 20);
    Assert.assertEquals(field.getLabel().getLeft(), 18);
    Assert.assertEquals(field.getLabel().getRight(), 114);
    Assert.assertEquals(field.getLabel().getTop(), 2281);
    Assert.assertEquals(field.getLabel().getBottom(), 2295);
    Assert.assertEquals(field.getLabel().getHeight(), 14);
    Assert.assertEquals(field.getLabel().getWidth(), 96);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 13 with Field

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

the class TestField method testNoMatchePosition.

@Test(groups = { "ut" })
public void testNoMatchePosition() {
    Field f1 = new Field(0, 100, 0, 20, "foobar", "field");
    Field f2 = new Field(100, 199, 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 14 with Field

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

the class TestField method testFromJsonRelatedField.

@Test(groups = { "ut" })
public void testFromJsonRelatedField() {
    Field field = Field.fromJson(new JSONObject("{" + "		\"class_id\": 4," + "		\"top\": 203," + "		\"bottom\": 225," + "		\"left\": 21," + "		\"right\": 351," + "		\"class_name\": \"field_with_label\"," + "		\"text\": \"Pr\\u00e9nom\"," + "		\"related_field\": {" + "			\"class_id\": 0," + "			\"top\": 205," + "			\"bottom\": 224," + "			\"left\": 76," + "			\"right\": 354," + "			\"class_name\": \"field\"," + "			\"text\": null," + "			\"related_field\": null," + "			\"with_label\": false," + "			\"width\": 278," + "			\"height\": 19" + "		}," + "		\"with_label\": true," + "		\"width\": 330," + "		\"height\": 22" + "	}"));
    Assert.assertEquals(field.getInnerFieldRectangle(), new Rectangle(76, 205, 278, 19));
}
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 15 with Field

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

the class TestImageFieldDetector method testDetectFieldsAndLabels.

/**
 * Check detector is called only once event if we detect fields and labeld
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testDetectFieldsAndLabels() 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);
    ImageFieldDetector detector = new ImageFieldDetector(image);
    List<Field> fields = detector.detectFields();
    List<Label> labels = detector.detectLabels();
    // detector is called only once
    verify(fieldDetectorConnector).detect(image, 1);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) JSONObject(kong.unirest.json.JSONObject) ImageFieldDetector(com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) 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