use of com.seleniumtests.connectors.selenium.fielddetector.Field 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);
}
use of com.seleniumtests.connectors.selenium.fielddetector.Field 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.Field 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));
}
use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.
the class TestLabel method testFieldAndLabelNotAligned2.
/**
* Field on the right, but not aligned horizontally
*
* ------
* Field
* ------
*
* -----
* Label
* -----
*/
@Test(groups = { "ut" })
public void testFieldAndLabelNotAligned2() {
Label label = Label.fromJson(new JSONObject("{" + " \"top\": 200," + " \"left\": 300," + " \"width\": 100," + " \"height\": 20," + " \"right\": 400," + " \"bottom\": 220," + " \"text\": \"My link Parent\"" + " }"));
Field field = Field.fromJson(new JSONObject("{" + " \"class_id\": 3," + " \"top\": 100," + " \"left\": 200," + " \"width\": 100," + " \"height\": 20," + " \"right\": 300," + " \"bottom\": 120," + " \"class_name\": \"radio_with_label\"," + " \"text\": \"= Value 4\"," + " \"related_field\": null," + " \"with_label\": true" + " }"));
Assert.assertFalse(label.isInside(field));
Assert.assertFalse(label.isFieldLeftOf(field));
Assert.assertFalse(label.isFieldRightOf(field));
Assert.assertFalse(label.isFieldAbove(field));
Assert.assertFalse(label.isFieldBelow(field));
}
use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.
the class TestErrorCauseFinder method testSearchInLastStepDetectedErrorMessage.
/**
* An error_message field is found. We try to relate it to a label
* @throws Exception
*/
@Test(groups = { "ut" })
public void testSearchInLastStepDetectedErrorMessage() throws Exception {
ITestResult testResult = Reporter.getCurrentTestResult();
TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
List<Label> labels = new ArrayList<>();
labels.add(new Label(0, 100, 0, 20, "ko"));
labels.add(new Label(0, 100, 100, 120, "nothing"));
List<Field> fields = new ArrayList<>();
fields.add(new Field(0, 100, 0, 20, "", ErrorCauseFinder.CLASS_ERROR_MESSAGE));
fields.add(new Field(0, 100, 200, 220, "", "field"));
when(imageFieldDetector.detectFields()).thenReturn(fields);
when(imageFieldDetector.detectLabels()).thenReturn(labels);
List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
Assert.assertEquals(causes.size(), 1);
Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_MESSAGE);
Assert.assertEquals(causes.get(0).getDescription(), "ko");
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Aggregations