use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateStabilityInfoWithDifferentAttributes.
@Test(groups = { "ut" })
public void testUpdateStabilityInfoWithDifferentAttributes() throws IOException {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
// write data to file we will then read
File elementInfoPath = ElementInfo.buildElementInfoPath(htmlElement);
FileUtils.write(elementInfoPath, JSON_INFO_FOO);
ElementInfo elInfo = spy(ElementInfo.getInstance(htmlElement));
Assert.assertEquals(elInfo.getTotalSearch(), 1);
doReturn(image).when(elInfo).getScreenshot();
// change attribute values (one added and one removed)
Map<String, Object> attributes = new HashMap<>();
attributes.put("data", "someData");
attributes.put("id", "foo");
when(driver.executeScript(ElementInfo.JAVASCRIPT_GET_ATTRIBUTES, element)).thenReturn(attributes);
elInfo.updateInfo(htmlElement);
// check stability indicators have been updated. Text indicator is reset to 0 as value has changed
Assert.assertEquals(elInfo.getTotalSearch(), 2);
Assert.assertEquals(elInfo.getTextStability(), 1);
Assert.assertEquals(elInfo.getTagStability(), 1);
Assert.assertEquals(elInfo.getRectangleStability(), 1);
Assert.assertEquals(elInfo.getAttributesStability().get("id"), (Integer) 1);
// reset as not found anymore
Assert.assertEquals(elInfo.getAttributesStability().get("class"), (Integer) 0);
// created
Assert.assertEquals(elInfo.getAttributesStability().get("data"), (Integer) 0);
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testCreateElementInfoWithLabelHavingOddCharacters.
/**
* If label contains some characters not supported by filesystem, replace them
*/
@Test(groups = { "ut" })
public void testCreateElementInfoWithLabelHavingOddCharacters() {
when(htmlElement.getLabel()).thenReturn("some%'/\\label");
ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
// check element info is created with basic information
Assert.assertNotNull(elInfo);
Assert.assertEquals(elInfo.getId(), "foo.bar.Page/some_label");
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateStabilityInfoWithDifferentElement.
/**
* When an element changed, its stability indicator is reset to 0
* @throws IOException
*/
@Test(groups = { "ut" })
public void testUpdateStabilityInfoWithDifferentElement() throws IOException {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
// write data to file we will then read
File elementInfoPath = ElementInfo.buildElementInfoPath(htmlElement);
FileUtils.write(elementInfoPath, JSON_INFO_FOO);
ElementInfo elInfo = spy(ElementInfo.getInstance(htmlElement));
Assert.assertEquals(elInfo.getTotalSearch(), 1);
doReturn(image).when(elInfo).getScreenshot();
// change text value
when(element.getText()).thenReturn("newText");
elInfo.updateInfo(htmlElement);
// check stability indicators have been updated. Text indicator is reset to 0 as value has changed
Assert.assertEquals(elInfo.getTotalSearch(), 2);
Assert.assertEquals(elInfo.getTextStability(), 0);
Assert.assertEquals(elInfo.getTagStability(), 1);
Assert.assertEquals(elInfo.getRectangleStability(), 1);
Assert.assertEquals(elInfo.getAttributesStability().get("id"), (Integer) 1);
}
Aggregations