use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class SeleniumRobotElementInfoServerConnector method getElementInfos.
/**
* Retrieve all element information from the server
* @return
*/
public List<ElementInfo> getElementInfos() {
if (!active) {
throw new SeleniumRobotServerException("Server is not active");
}
try {
GetRequest request = buildGetRequest(url + LIST_ELEMENT_INFO_API_URL).queryString("application", applicationId).queryString("version", versionId).queryString("format", "json");
JSONArray eiJson = getJSonArray(request);
List<ElementInfo> elementInfos = new ArrayList<>();
for (int i = 0; i < eiJson.length(); i++) {
ElementInfo ei = ElementInfo.readFromJson(eiJson.getJSONObject(i).toString());
elementInfos.add(ei);
}
return elementInfos;
} catch (UnirestException | JSONException e) {
throw new SeleniumRobotServerException("cannot get element infos", e);
}
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testElementInfoAlreadyExists.
/**
* Element info is not recreated, but updated when element has already been successfully searched
*/
@Test(groups = { "it" })
public void testElementInfoAlreadyExists() {
// element information will be created with the following command
DriverTestPage.textElement.getTagName();
File elementInfoPath = ElementInfo.buildElementInfoPath(DriverTestPage.textElement);
ElementInfo elInfo = ElementInfo.readFromJsonFile(elementInfoPath);
// element only searched once
Assert.assertEquals(elInfo.getTotalSearch(), 1);
DriverTestPage.textElement.getTagName();
ElementInfo newElInfo = ElementInfo.readFromJsonFile(elementInfoPath);
// test search done twice
Assert.assertEquals(newElInfo.getTotalSearch(), 2);
// test search done twice
Assert.assertEquals(newElInfo.getTagStability(), 1);
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testScrollingForScreenshot.
/**
* Check scrolling is done to take screenshot
* No error should be raised here, meaning that the capture has correctly been done
* Check a screenshot has been done
*/
@Test(groups = { "it" })
public void testScrollingForScreenshot() {
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 0);");
DriverTestPage.scrollButton.click();
File elementInfoPath = ElementInfo.buildElementInfoPath(DriverTestPage.scrollButton);
ElementInfo elInfo = ElementInfo.readFromJsonFile(elementInfoPath);
Assert.assertTrue(!elInfo.getB64Image().isEmpty());
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testElementModified.
/**
* Info file recreated when search criteria has been modified
*/
@Test(groups = { "it" })
public void testElementModified() {
// element information will be created with the following command
DriverTestPage.textElement.getTagName();
File elementInfoPath = ElementInfo.buildElementInfoPath(DriverTestPage.textElement);
ElementInfo elInfo = ElementInfo.readFromJsonFile(elementInfoPath);
// element only searched once
Assert.assertEquals(elInfo.getTotalSearch(), 1);
// change locator and check file has been regenerated (totalsearch == 1)
try {
DriverTestPage.textElement.setBy(By.name("textField"));
DriverTestPage.textElement.getTagName();
ElementInfo newElInfo = ElementInfo.readFromJsonFile(elementInfoPath);
// test search done once because locator has been changed
Assert.assertEquals(newElInfo.getTotalSearch(), 1);
// test search done twice
Assert.assertEquals(newElInfo.getTagStability(), 0);
} finally {
DriverTestPage.textElement.setBy(By.id("text2"));
}
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testReadFromJson.
/**
* Check we are able to read an element info file and extract information
* @throws IOException
*/
@Test(groups = { "ut" })
public void testReadFromJson() throws IOException {
File einfoFile = File.createTempFile("elementInfo", ".json");
FileUtils.write(einfoFile, JSON_INFO);
einfoFile.deleteOnExit();
ElementInfo elementInfo = ElementInfo.readFromJsonFile(einfoFile);
Assert.assertEquals(elementInfo.getName(), "button after scroll");
Assert.assertEquals(elementInfo.getId(), "com.seleniumtests.it.driver.support.pages.DriverTestPage/button_after_scroll");
Assert.assertEquals(elementInfo.getText(), "set");
Assert.assertEquals(elementInfo.getTagName(), "button");
Assert.assertEquals(elementInfo.getLocator(), "By.id: buttonScroll");
Assert.assertEquals(elementInfo.getCoordX(), (Integer) 8);
Assert.assertNotNull(elementInfo.getB64Image());
Assert.assertEquals(elementInfo.getAttributes().size(), 2);
Assert.assertEquals(elementInfo.getAttributes().get("id"), "buttonScroll");
Assert.assertEquals(elementInfo.getTotalSearch(), 8);
Assert.assertEquals(elementInfo.getTextStability(), 4);
Assert.assertEquals((int) elementInfo.getAttributesStability().get("id"), 5);
}
Aggregations