Search in sources :

Example 6 with ImageFieldDetector

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

the class TestImageFieldDetector method testDetectLabels.

@Test(groups = { "ut" })
public void testDetectLabels() 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<Label> labels = new ImageFieldDetector(image, 1, FieldType.ALL_FORM_FIELDS).detectLabels();
    Assert.assertEquals(labels.size(), 2);
}
Also used : 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)

Example 7 with ImageFieldDetector

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

the class TestImageFieldDetector method testDetectLabelsWrongFormat.

@Test(groups = { "ut" })
public void testDetectLabelsWrongFormat() 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" + "	}]" + "} ");
    File image = createImageFromResource("ti/form_picture.png");
    when(fieldDetectorConnector.detect(image, 2)).thenReturn(obj);
    SeleniumTestsContextManager.getGlobalContext().setFieldDetectorInstance(fieldDetectorConnector);
    List<Label> labels = new ImageFieldDetector(image, 2).detectLabels();
    Assert.assertEquals(labels.size(), 0);
}
Also used : 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)

Example 8 with ImageFieldDetector

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

the class TestImageFieldDetector method testDetectFieldsWrongFormat.

@Test(groups = { "ut" })
public void testDetectFieldsWrongFormat() throws IOException {
    JSONObject obj = new JSONObject("{" + "	\"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(), 0);
}
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)

Example 9 with ImageFieldDetector

use of com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector 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)

Example 10 with ImageFieldDetector

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

the class TestImageFieldDetector method testDetectErrorMessageAndFields.

@Test(groups = { "ut" })
public void testDetectErrorMessageAndFields() throws IOException {
    JSONObject obj = new JSONObject("{" + "	\"fields\": [{" + "		\"class_id\": 3," + "		\"top\": 674," + "		\"bottom\": 696," + "		\"left\": 20," + "		\"right\": 141," + "		\"class_name\": \"error_field\"," + "		\"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\": \"error_message\"," + "		\"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.detectError(image, 1)).thenReturn(obj);
    SeleniumTestsContextManager.getGlobalContext().setFieldDetectorInstance(fieldDetectorConnector);
    List<Field> fields = new ImageFieldDetector(image, 1, FieldType.ERROR_MESSAGES_AND_FIELDS).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

ImageFieldDetector (com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector)10 File (java.io.File)9 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)8 Test (org.testng.annotations.Test)7 MockitoTest (com.seleniumtests.MockitoTest)6 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)6 JSONObject (kong.unirest.json.JSONObject)6 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 GenericTest (com.seleniumtests.GenericTest)1 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1 Snapshot (com.seleniumtests.reporter.logger.Snapshot)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 Rectangle (java.awt.Rectangle)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Point (org.openqa.selenium.Point)1 ScreenshotException (org.openqa.selenium.remote.ScreenshotException)1 SkipException (org.testng.SkipException)1