use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testCreateElementInfoWithChangedLocator.
/**
* When the element locator has changed compared to what is stored on disk, delete the file and create an new ElementInfo
* @throws IOException
*/
@Test(groups = { "ut" })
public void testCreateElementInfoWithChangedLocator() 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);
// change HtmlElement locator
when(htmlElement.getBy()).thenReturn(By.name("bar"));
ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
// we should get a new element info not fully initialized
Assert.assertNull(elInfo.getTagName());
Assert.assertEquals(elInfo.getLocator(), "By.name: bar");
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateStabilityInfoWithSameElement.
/**
* When the strictly same element is found, increment stability information
* @throws IOException
*/
@Test(groups = { "ut" })
public void testUpdateStabilityInfoWithSameElement() 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);
Assert.assertEquals(elInfo.getTextStability(), 0);
Assert.assertEquals(elInfo.getTagStability(), 0);
Assert.assertEquals(elInfo.getRectangleStability(), 0);
Assert.assertEquals(elInfo.getAttributesStability().get("id"), (Integer) 0);
doReturn(image).when(elInfo).getScreenshot();
elInfo.updateInfo(htmlElement);
// check stability indicators have been updated
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);
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class SeleniumRobotElementInfoServerConnector method getAndStoreElementInfos.
/**
* get and store element info to json file
*/
public void getAndStoreElementInfos() {
for (ElementInfo ei : getElementInfos()) {
try {
ei.exportToJsonFile(false, null);
ei.exportToJsonFile(true, null);
} catch (IOException e) {
logger.error("error exporting ElementInfo to file: " + e.getMessage());
}
}
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class SeleniumRobotElementInfoServerConnector method updateElementInfoToServer.
/**
* compare original checkout to updated data. Send updated data to server
*/
public void updateElementInfoToServer() {
Map<String, ElementInfo> referenceElementInfos = ElementInfo.getAllStoredElementInfos(true);
// get reference
for (Entry<String, ElementInfo> currentElementInfoEntry : ElementInfo.getAllStoredElementInfos(false).entrySet()) {
ElementInfo currentElementInfo = currentElementInfoEntry.getValue();
ElementInfo referenceElementInfo = referenceElementInfos.get(currentElementInfoEntry.getKey());
// if no reference exists, create it on server
if (referenceElementInfo == null) {
// TODO
} else if (!currentElementInfo.getLastUpdate().equals(referenceElementInfo.getLastUpdate())) {
try {
MultipartBody request = buildPatchRequest(url + ELEMENT_INFO_API_URL).field("application", applicationId).field("uuid", currentElementInfo.getId()).field("name", currentElementInfo.getName());
if (currentElementInfo.getCoordX().equals(referenceElementInfo.getCoordX())) {
request = request.field("coordX", currentElementInfo.getCoordX().toString());
}
if (currentElementInfo.getCoordY().equals(referenceElementInfo.getCoordY())) {
request = request.field("coordY", currentElementInfo.getCoordY().toString());
}
if (currentElementInfo.getWidth().equals(referenceElementInfo.getWidth())) {
request = request.field("width", currentElementInfo.getWidth().toString());
}
if (currentElementInfo.getHeight().equals(referenceElementInfo.getHeight())) {
request = request.field("height", currentElementInfo.getHeight().toString());
}
if (currentElementInfo.getLocator().equals(referenceElementInfo.getLocator())) {
request = request.field("locator", currentElementInfo.getLocator());
}
if (currentElementInfo.getTagName().equals(referenceElementInfo.getTagName())) {
request = request.field("tagName", currentElementInfo.getTagName());
}
if (currentElementInfo.getText().equals(referenceElementInfo.getText())) {
request = request.field("text", currentElementInfo.getText());
}
if (currentElementInfo.getB64Image().equals(referenceElementInfo.getB64Image())) {
request = request.field("b64Image", currentElementInfo.getB64Image());
}
if (currentElementInfo.getAttributes().equals(referenceElementInfo.getAttributes())) {
request = request.field("attributes", new JSONObject(currentElementInfo.getAttributes()).toString());
}
if (currentElementInfo.getTotalSearch() != referenceElementInfo.getTotalSearch()) {
request = request.field("totalSearch", "+" + Integer.toString(currentElementInfo.getTotalSearch() - referenceElementInfo.getTotalSearch()));
}
if (currentElementInfo.getTagStability() != referenceElementInfo.getTagStability()) {
request = request.field("tagStability", "+" + Integer.toString(currentElementInfo.getTagStability() - referenceElementInfo.getTagStability()));
}
if (currentElementInfo.getTextStability() != referenceElementInfo.getTextStability()) {
request = request.field("textStability", "+" + Integer.toString(currentElementInfo.getTextStability() - referenceElementInfo.getTextStability()));
}
if (currentElementInfo.getRectangleStability() != referenceElementInfo.getRectangleStability()) {
request = request.field("rectangleStability", "+" + Integer.toString(currentElementInfo.getRectangleStability() - referenceElementInfo.getRectangleStability()));
}
if (currentElementInfo.getB64ImageStability() != referenceElementInfo.getB64ImageStability()) {
request = request.field("b64ImageStability", "+" + Integer.toString(currentElementInfo.getB64ImageStability() - referenceElementInfo.getB64ImageStability()));
}
if (currentElementInfo.getAttributesStability() != referenceElementInfo.getAttributesStability()) {
Map<String, Object> attributeStabilityDiff = new HashMap<>();
for (String attribute : currentElementInfo.getAttributesStability().keySet()) {
attributeStabilityDiff.put(attribute, "+" + Integer.toString(currentElementInfo.getAttributesStability().get(attribute) - referenceElementInfo.getAttributesStability().getOrDefault(attribute, 0)));
}
request = request.field("attributesStability", new JSONObject(attributeStabilityDiff).toString());
}
getJSonResponse(request);
} catch (UnirestException e) {
logger.warn("cannot update element info: " + e.getMessage());
}
}
}
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testNewElementInfo.
/**
* Test the info file is created when element is found
* @throws IOException
*/
@Test(groups = { "it" })
public void testNewElementInfo() throws IOException {
try {
DriverTestPage.textElement.sendKeys("youpi");
} finally {
DriverTestPage.resetButton.click();
}
// check file has been created
File elementInfoPath = ElementInfo.buildElementInfoPath(DriverTestPage.textElement);
Assert.assertTrue(elementInfoPath.isFile());
ElementInfo elInfo = ElementInfo.readFromJsonFile(elementInfoPath);
// element only searched once
Assert.assertEquals(elInfo.getTotalSearch(), 1);
// check some element information have been retrieved. We do not check all as it's already done in unit tests
Assert.assertEquals(elInfo.getAttributes().size(), 2);
}
Aggregations