Search in sources :

Example 1 with ElementInfo

use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.

the class TestElementInfo method testUpdateInfoForAppTesting.

/**
 * create element information simulating application testing. In this mode, some information are not available (those specific to web browsing): tagName and attributes
 */
@Test(groups = { "ut" })
public void testUpdateInfoForAppTesting() {
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APP);
    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);
    // tagname not initialized for apps
    Assert.assertEquals(elInfo.getTagName(), "");
    // attributes not initalized for apps
    Assert.assertEquals(elInfo.getAttributes().size(), 0);
    Assert.assertEquals(elInfo.getB64Image(), "ABCD");
}
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 2 with ElementInfo

use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.

the class TestElementInfo method testCreateNewInfo.

/**
 * Create a new elementInfo
 */
@Test(groups = { "ut" })
public void testCreateNewInfo() {
    ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
    // check element info is created with basic information
    Assert.assertNotNull(elInfo);
    Assert.assertEquals(elInfo.getId(), "foo.bar.Page/mylabel");
    Assert.assertEquals(elInfo.getName(), "mylabel");
    Assert.assertEquals(elInfo.getLocator(), "By.id: foo");
    Assert.assertNull(elInfo.getTagName());
    Assert.assertNull(elInfo.getText());
    Assert.assertEquals((Integer) 0, elInfo.getCoordX());
    Assert.assertEquals((Integer) 0, elInfo.getCoordY());
    Assert.assertEquals((Integer) 0, elInfo.getWidth());
    Assert.assertEquals((Integer) 0, elInfo.getHeight());
    Assert.assertEquals(elInfo.getTotalSearch(), 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 3 with ElementInfo

use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.

the class TestElementInfo method testReadFromNonExistentJson.

/**
 * Check we return null if the file information cannot be found
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testReadFromNonExistentJson() throws IOException {
    ElementInfo elementInfo = ElementInfo.readFromJsonFile(new File("foo.json"));
    Assert.assertNull(elementInfo);
}
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 4 with ElementInfo

use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.

the class TestElementInfo method testCreateNewInfoWithFalseMode.

/**
 * Do not create new ElementInfo, do not even search as we forbid this
 */
@Test(groups = { "ut" })
public void testCreateNewInfoWithFalseMode() {
    SeleniumTestsContextManager.getThreadContext().setAdvancedElementSearch("false");
    ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
    // check element info is created with basic information
    Assert.assertNull(elInfo);
}
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 5 with ElementInfo

use of com.seleniumtests.uipage.htmlelements.ElementInfo in project seleniumRobot by bhecquet.

the class TestElementInfo method testCreateElementInfoWithExistingInfo.

/**
 * Test case where the ElementInfo already exists on disk
 * We should get it
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testCreateElementInfoWithExistingInfo() 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");
}
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)

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