Search in sources :

Example 26 with Field

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);
}
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 27 with Field

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));
}
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 28 with 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));
}
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 29 with 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));
}
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 30 with 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));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) 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