Search in sources :

Example 11 with ElementInfo

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);
    }
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) GetRequest(kong.unirest.GetRequest) JSONArray(kong.unirest.json.JSONArray) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 12 with ElementInfo

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);
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) File(java.io.File) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest) Test(org.testng.annotations.Test)

Example 13 with ElementInfo

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());
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) File(java.io.File) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest) Test(org.testng.annotations.Test)

Example 14 with ElementInfo

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"));
    }
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) File(java.io.File) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest) Test(org.testng.annotations.Test)

Example 15 with ElementInfo

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);
}
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