Search in sources :

Example 16 with ElementInfo

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);
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 17 with ElementInfo

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");
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 18 with ElementInfo

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(), "");
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 19 with ElementInfo

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"));
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 20 with ElementInfo

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);
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

ElementInfo (com.seleniumtests.uipage.htmlelements.ElementInfo)23 Test (org.testng.annotations.Test)20 MockitoTest (com.seleniumtests.MockitoTest)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 File (java.io.File)13 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)4 HashMap (java.util.HashMap)2 UnirestException (kong.unirest.UnirestException)2 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 GetRequest (kong.unirest.GetRequest)1 MultipartBody (kong.unirest.MultipartBody)1 JSONArray (kong.unirest.json.JSONArray)1 JSONException (kong.unirest.json.JSONException)1 JSONObject (kong.unirest.json.JSONObject)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1