use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateInfo.
/**
* Create a new elementInfo in Full mode and Web content
* We should get all element information for web content
*/
@Test(groups = { "ut" })
public void testUpdateInfo() {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
ElementInfo elInfo = spy(ElementInfo.getInstance(htmlElement));
doReturn(image).when(elInfo).getScreenshot();
elInfo.updateInfo(htmlElement);
// check element info is created with basic information
Assert.assertNotNull(elInfo);
Assert.assertEquals(elInfo.getText(), "sometext");
Assert.assertEquals(elInfo.getCoordX(), (Integer) 10);
Assert.assertEquals(elInfo.getCoordY(), (Integer) 20);
Assert.assertEquals(elInfo.getHeight(), (Integer) 30);
Assert.assertEquals(elInfo.getWidth(), (Integer) 40);
Assert.assertEquals(elInfo.getTotalSearch(), 1);
Assert.assertEquals(elInfo.getTagName(), "h1");
Assert.assertEquals(elInfo.getAttributes().get("class"), "someClass");
Assert.assertEquals(elInfo.getB64Image(), "ABCD");
// indicators are initialized
Assert.assertEquals(elInfo.getTextStability(), 0);
Assert.assertEquals(elInfo.getTagStability(), 0);
Assert.assertEquals(elInfo.getRectangleStability(), 0);
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateExistingInfo.
/**
* Test case where the ElementInfo already exists on disk
* We should get it and update information in there
* @throws IOException
*/
@Test(groups = { "ut" })
public void testUpdateExistingInfo() 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));
// we should get the existing information
Assert.assertEquals(elInfo.getTagName(), "h1");
doReturn(image).when(elInfo).getScreenshot();
// change information of the underlying element
when(element.getTagName()).thenReturn("h2");
elInfo.updateInfo(htmlElement);
Assert.assertEquals(elInfo.getTagName(), "h2");
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateInfoInDomMode.
/**
* create element information in dom mode. In this mode, element capture is not done
*/
@Test(groups = { "ut" })
public void testUpdateInfoInDomMode() {
SeleniumTestsContextManager.getThreadContext().setAdvancedElementSearch("dom");
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
ElementInfo elInfo = spy(ElementInfo.getInstance(htmlElement));
doReturn(image).when(elInfo).getScreenshot();
elInfo.updateInfo(htmlElement);
// in dom mode, no picture generated
Assert.assertNotNull(elInfo);
Assert.assertEquals(elInfo.getText(), "sometext");
Assert.assertEquals(elInfo.getB64Image(), "");
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testExportToJson.
@Test(groups = { "ut" })
public void testExportToJson() throws IOException {
// get an elementInfo from file, as it is complete (no mocks)
File einfoFile = File.createTempFile("elementInfo", ".json");
FileUtils.write(einfoFile, JSON_INFO);
einfoFile.deleteOnExit();
ElementInfo elementInfo = ElementInfo.readFromJsonFile(einfoFile);
File out = elementInfo.exportToJsonFile(false, htmlElement);
out.deleteOnExit();
Assert.assertTrue(out.exists());
String content = FileUtils.readFileToString(out);
Assert.assertTrue(content.contains("\"id\":\"com.seleniumtests.it.driver.support.pages.DriverTestPage/button_after_scroll\""));
// path updated
Assert.assertTrue(content.contains("mylabel.json"));
}
use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.
the class TestElementInfo method testUpdateInfoWithoutRealElement.
@Test(groups = { "ut" }, expectedExceptions = CustomSeleniumTestsException.class)
public void testUpdateInfoWithoutRealElement() {
ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
when(htmlElement.getRealElement()).thenReturn(null);
elInfo.updateInfo(htmlElement);
}
Aggregations