Search in sources :

Example 21 with ElementInfo

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

the class TestElementInfo method testUpdateStabilityInfoWithDifferentAttributes.

@Test(groups = { "ut" })
public void testUpdateStabilityInfoWithDifferentAttributes() 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);
    doReturn(image).when(elInfo).getScreenshot();
    // change attribute values (one added and one removed)
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("data", "someData");
    attributes.put("id", "foo");
    when(driver.executeScript(ElementInfo.JAVASCRIPT_GET_ATTRIBUTES, element)).thenReturn(attributes);
    elInfo.updateInfo(htmlElement);
    // check stability indicators have been updated. Text indicator is reset to 0 as value has changed
    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);
    // reset as not found anymore
    Assert.assertEquals(elInfo.getAttributesStability().get("class"), (Integer) 0);
    // created
    Assert.assertEquals(elInfo.getAttributesStability().get("data"), (Integer) 0);
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) HashMap(java.util.HashMap) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 22 with ElementInfo

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

the class TestElementInfo method testCreateElementInfoWithLabelHavingOddCharacters.

/**
 * If label contains some characters not supported by filesystem, replace them
 */
@Test(groups = { "ut" })
public void testCreateElementInfoWithLabelHavingOddCharacters() {
    when(htmlElement.getLabel()).thenReturn("some%'/\\label");
    ElementInfo elInfo = ElementInfo.getInstance(htmlElement);
    // check element info is created with basic information
    Assert.assertNotNull(elInfo);
    Assert.assertEquals(elInfo.getId(), "foo.bar.Page/some_label");
}
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 23 with ElementInfo

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

the class TestElementInfo method testUpdateStabilityInfoWithDifferentElement.

/**
 * When an element changed, its stability indicator is reset to 0
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testUpdateStabilityInfoWithDifferentElement() 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);
    doReturn(image).when(elInfo).getScreenshot();
    // change text value
    when(element.getText()).thenReturn("newText");
    elInfo.updateInfo(htmlElement);
    // check stability indicators have been updated. Text indicator is reset to 0 as value has changed
    Assert.assertEquals(elInfo.getTotalSearch(), 2);
    Assert.assertEquals(elInfo.getTextStability(), 0);
    Assert.assertEquals(elInfo.getTagStability(), 1);
    Assert.assertEquals(elInfo.getRectangleStability(), 1);
    Assert.assertEquals(elInfo.getAttributesStability().get("id"), (Integer) 1);
}
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