Example usage for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated.

Prototype

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page.

Usage

From source file:influent.selenium.tests.EntityDetailsTest.java

License:MIT License

@Test
public void entityDetailsTest() {
    getFlowViewResults("name:\"joe\" countryCode:\"PE\" datatype:loan matchtype:\"any\"");

    List<WebElement> elements = driver.findElements(By.className("baseballcardContainer"));

    WebElement card1 = null;/*  w  w  w . ja v a  2  s .  com*/
    for (WebElement webElement : elements) {
        if (webElement.isDisplayed()) {
            if (card1 == null) {
                card1 = webElement;
                break;
            }
        }
    }

    if (card1 == null) {
        throw new AssertionError("Couldn't find: baseballcardContainer element");
    }

    card1.click();

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    WebElement element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("details")));

    element = driver.findElement(By.className("detailsTitle"));
    assertEquals("Account Details", element.getText());

    element = driver.findElement(By.className("detailsEntityLabel"));
    assertEquals("Joe. Peru, PUCALLPA", element.getText());

    elements = driver.findElements(By.className("detailsIcon"));
    element = SeleniumUtils.getDisplayedElement(elements);
    String src = element.getAttribute("src");
    assertEquals("http://localhost:8080/kiva/rest/icon/aperture-hscb/Person?iconWidth=32&iconHeight=32", src);

    element = driver.findElement(By.id("entityDetailsImageLink"));
    String href = element.getAttribute("href");
    assertEquals("http://www.kiva.org/img/w400/1118387.jpg", href);

    elements = driver.findElements(By.tagName("tr"));
    WebElement row1 = null;
    WebElement row2 = null;
    for (WebElement webElement : elements) {
        if (webElement.isDisplayed()) {
            if (row1 == null) {
                row1 = webElement;
            } else {
                row2 = webElement;
                break;
            }
        }
    }
    assertEquals("uid: a.loan.b438363", row1.getText());
    assertEquals("Posted Date: Jun 1, 2012", row2.getText());
}

From source file:influent.selenium.tests.EntityDetailsTest.java

License:MIT License

@Test
public void clusterSummaryDetailsTest() {
    getFlowViewResults("visionfund");

    //Test a card that has no transactions
    List<WebElement> elements = driver.findElements(By.className("baseballcardContainer"));
    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    element.click();/*from   w  w w . j av a 2  s  .  c o m*/

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("details")));

    element = driver.findElement(By.className("detailsTitle"));
    assertEquals("Account Details", element.getText());

    element = driver.findElement(By.className("detailsEntityLabel"));
    assertEquals("VisionFund Albania", element.getText());

    elements = driver.findElements(By.className("detailsIcon"));
    element = SeleniumUtils.getDisplayedElement(elements);
    String src = element.getAttribute("src");
    assertEquals(
            "http://localhost:8080/kiva/rest/icon/aperture-hscb/Organization?iconWidth=32&iconHeight=32&role=business",
            src);

    element = driver.findElement(By.id("entityDetailsImageLink"));
    String href = element.getAttribute("href");
    assertEquals("http://www.kiva.org/img/w400/1092590.jpg", href);

    elements = driver.findElements(By.tagName("tr"));
    WebElement row1 = null;
    WebElement row2 = null;
    for (WebElement webElement : elements) {
        if (webElement.isDisplayed()) {
            if (row1 == null) {
                row1 = webElement;
            } else {
                row2 = webElement;
                break;
            }
        }
    }
    assertEquals("uid: o.partner.p239", row1.getText());
    assertEquals("partners_cc: AL", row2.getText());
}

From source file:influent.selenium.tests.FlowViewTests.java

License:MIT License

@Test
public void columnLabelTest() {
    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }/*from ww  w .j  a  v  a  2  s .  c o  m*/

    element.sendKeys("joe");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar")));
    List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]"));
    WebElement switchToFlowButton = null;

    for (WebElement e : switchViewButtons) {
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementCount = 0;
    for (WebElement e : dataIdElements) {
        if (elementCount == 1) {
            e.click();
            break;
        }
        elementCount++;
    }
    switchToFlowButton.click();
    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".insideBaseballCard")));

    //Test that labels are visible in intial state
    elements = driver.findElements(By.className("columnHint"));
    assertEquals(2, elements.size());

    //assertEquals("FROM ACCOUNTS", elements.get(0).getText());
    //assertEquals("TO ACCOUNTS", elements.get(1).getText());

    //Test column labels are removed after cards are added to column
    elements = driver.findElements(By.className("baseballcardContainer"));
    element = SeleniumUtils.getDisplayedElement(elements);
    //Click card so add to file buttons appear
    element.click();

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    element = element.findElement(By.cssSelector("[title='add to file']"));
    element.click();

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    //find card again
    element = driver.findElement(By.className("file"));
    element = element.findElement(By.className("baseballcardContainer"));

    //Click card again so branch right button appears
    element.click();

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    element = (new WebDriverWait(driver, 120)).until(ExpectedConditions
            .presenceOfElementLocated(By.cssSelector("[title='branch right to outflowing destinations']")));

    element.click();

    //Wait a few seconds for page to load. This is needed despite waiting for presence of element
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    elements = driver.findElements(By.className("columnHint"));
    assertEquals(0, elements.size());
}

From source file:influent.selenium.tests.FlowViewTests.java

License:MIT License

@Test
public void displayClusterSummary() {
    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }/*from w w  w  . j a v  a  2 s  .  c  om*/

    element.sendKeys("visionfund");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar")));
    List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]"));
    WebElement switchToFlowButton = null;

    for (WebElement e : switchViewButtons) {
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementCount = 0;
    for (WebElement e : dataIdElements) {
        if (elementCount == 1) {
            e.click();
            break;
        }
        elementCount++;
    }
    switchToFlowButton.click();
    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".insideBaseballCard")));
    if (firstTransactionResult == null) {
        throw new AssertionError(
                "Couldn't find any transaction results.   Either timed out or search returned no transactions!");
    }
}

From source file:influent.selenium.tests.OperationsBarTest.java

License:MIT License

@Test
public void accountsToTransactionsTest() {

    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }/*ww w. j a  va  2s  .c o  m*/

    element.sendKeys("daniel");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar")));
    List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]"));
    WebElement switchToTransactionsButton = null;
    WebElement switchToFlowButton = null;
    WebElement switchToAccountsButton = null;
    //Get the operations bar buttons, but also make sure they are in the correct order
    for (WebElement e : switchViewButtons) {
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
            if (switchToTransactionsButton == null || switchToAccountsButton == null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        } else if (switchTo.equals(SeleniumUtils.TRANSACTIONS_NAME)) {
            switchToTransactionsButton = e;
            if (switchToFlowButton != null || switchToAccountsButton == null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        } else if (switchTo.equals("")) {
            switchToAccountsButton = e;
            if (switchToFlowButton != null && switchToTransactionsButton != null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }
    if (switchToTransactionsButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to transactions view in infOperationsBar");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementsToSelect = 2;
    int elementsSelected = 0;
    for (WebElement e : dataIdElements) {
        e.click();
        elementsSelected++;
        if (elementsToSelect == elementsSelected) {
            break;
        }
    }
    switchToTransactionsButton.click();
    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".transactionsSearchResult")));
    if (firstTransactionResult == null) {
        throw new AssertionError(
                "Couldn't find any transaction results.   Either timed out or search returned no transactions!");
    }
}

From source file:influent.selenium.tests.OperationsBarTest.java

License:MIT License

@Test
public void accountsToFlowTest() {

    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }//from  w  ww. j  av a2s  . com

    element.sendKeys("daniel");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar")));
    List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]"));
    WebElement switchToTransactionsButton = null;
    WebElement switchToFlowButton = null;
    for (WebElement e : switchViewButtons) {
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
        } else if (switchTo.equals(SeleniumUtils.TRANSACTIONS_NAME)) {
            switchToTransactionsButton = e;
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }
    if (switchToTransactionsButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to transactions view in infOperationsBar");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementsToSelect = 2;
    int elementsSelected = 0;
    for (WebElement e : dataIdElements) {
        e.click();
        elementsSelected++;
        if (elementsToSelect == elementsSelected) {
            break;
        }
    }
    switchToFlowButton.click();
    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".insideBaseballCard")));
    if (firstTransactionResult == null) {
        throw new AssertionError(
                "Couldn't find any transaction results.   Either timed out or search returned no transactions!");
    }
}

From source file:influent.selenium.tests.OperationsBarTest.java

License:MIT License

@Test
public void transactionsToAccountsTest() {

    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_TRANSACTIONS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }//from w  ww .  j a v a  2 s .c o  m

    element.sendKeys("from:a.loan.b311953 to:a.loan.b311953 datatype:loan");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementsToSelect = 2;
    int elementsSelected = 0;
    for (WebElement e : dataIdElements) {
        e.click();
        elementsSelected++;
        if (elementsToSelect == elementsSelected) {
            break;
        }
    }

    List<WebElement> switchViewButtons = driver.findElements(By.className("btn-operationsBar"));

    WebElement switchToAccountsButton = null;
    WebElement switchToFlowButton = null;
    WebElement switchToTransactionsButton = null;
    for (WebElement e : switchViewButtons) {
        if (!e.isDisplayed()) {
            continue;
        }
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
            if (switchToTransactionsButton == null || switchToAccountsButton == null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        } else if (switchTo.equals(SeleniumUtils.ACCOUNTS_NAME)) {
            switchToAccountsButton = e;
            if (switchToFlowButton != null && switchToTransactionsButton != null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        } else if (switchTo.equals("")) {
            switchToTransactionsButton = e;
            if (switchToFlowButton != null || switchToAccountsButton == null) {
                throw new AssertionError("Operations bar buttons are not in the correct order");
            }
        }
    }

    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }
    if (switchToAccountsButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to accounts view in infOperationsBar");
    }

    switchToAccountsButton.click();
    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".accountsSearchResult")));
    if (firstTransactionResult == null) {
        throw new AssertionError(
                "Couldn't find any transaction results.   Either timed out or search returned no transactions!");
    }
}

From source file:influent.selenium.tests.OperationsBarTest.java

License:MIT License

@Test
public void transacitonsToFlowTest() {

    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_TRANSACTIONS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }/* w ww . j  a v a 2s.c  om*/

    element.sendKeys("from:a.loan.b311953 to:a.loan.b311953 datatype:loan");
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));
    if (element == null) {
        throw new AssertionError("Couldn't find any search results");
    }

    // Select first two search results with a data id
    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementsToSelect = 2;
    int elementsSelected = 0;
    for (WebElement e : dataIdElements) {
        e.click();
        elementsSelected++;
        if (elementsToSelect == elementsSelected) {
            break;
        }
    }

    List<WebElement> switchViewButtons = driver.findElements(By.className("btn-operationsBar"));
    WebElement switchToAccountsButton = null;
    WebElement switchToFlowButton = null;
    for (WebElement e : switchViewButtons) {
        if (!e.isDisplayed()) {
            continue;
        }
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
        } else if (switchTo.equals(SeleniumUtils.ACCOUNTS_NAME)) {
            switchToAccountsButton = e;
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }
    if (switchToAccountsButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to accounts view in infOperationsBar");
    }

    switchToFlowButton.click();

    WebElement firstTransactionResult = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".insideBaseballCard")));
    if (firstTransactionResult == null) {
        throw new AssertionError(
                "Couldn't find any transaction results.   Either timed out or search returned no transactions!");
    }
}

From source file:influent.selenium.tests.TransactionsSearchResultsTest.java

License:MIT License

/**
 * Runs a query and checks that all of the results are as expected
 * @param query/*from  w  ww.j av  a2  s  .  co m*/
 * @param expectedNumResults
 * @param expectedResults
 *   An array of expected search results. Each search result should be in the form:<br>
 *   { int index, String date, String to, String from }
 */
private void validateSearchResults(String query, int expectedNumResults, Object expectedResults[][]) {
    List<WebElement> elements = driver.findElements(By.cssSelector("#influent-filterbar-search-input"));

    //sort the expected results so we don't do extra work jumping between pages
    Arrays.sort(expectedResults, new Comparator<Object[]>() {
        @Override
        public int compare(Object[] o1, Object[] o2) {
            return ((Integer) o1[0]).compareTo((Integer) o2[0]);
        }

    });

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-filterbar-search-input element");
    }

    element.clear(); //clear the text from the input box first
    element.sendKeys(query); //pass in the query

    elements = driver.findElements(By.cssSelector(".btn-default"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: btn-default element");
    }

    element.click();

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".simpleSearchSummary")));
    assertEquals("Showing 1 - " + Math.min(expectedNumResults, MAX_NUM_RESULTS_PER_PAGE) + " of "
            + expectedNumResults + " results", element.getText());

    for (Object[] expectedResult : expectedResults) {
        //get the search result index this expected result refers to
        int resultNum = (Integer) expectedResult[0];

        //find the search result element
        WebElement searchResult = getSearchResult(resultNum);
        Assert.assertNotNull("Couldn't find search result " + resultNum + " for query: '" + query + "'",
                searchResult);

        //check that the results are as expected
        assertSearchResult((String) expectedResult[1], (String) expectedResult[2], (String) expectedResult[3],
                searchResult);
    }
}

From source file:influent.selenium.tests.TransactionsTableTest.java

License:MIT License

private void getFlowViewResults(String query, int numCards, boolean expand) {

    SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS);

    List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input"));

    WebElement element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element");
    }//from   ww  w  . ja v a  2s .  com

    element.sendKeys(query);
    elements = driver.findElements(By.className("infGoSearch"));
    element = SeleniumUtils.getDisplayedElement(elements);

    if (element == null) {
        throw new AssertionError("Couldn't find: infGoSearch element");
    }

    element.click();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {

    }
    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts")));

    element = (new WebDriverWait(driver, 120))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar")));
    List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]"));
    WebElement switchToFlowButton = null;
    for (WebElement e : switchViewButtons) {
        String switchTo = e.getAttribute("switchesto");
        if (switchTo.equals(SeleniumUtils.FLOW_NAME)) {
            switchToFlowButton = e;
        }
    }
    if (switchToFlowButton == null) {
        throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar");
    }

    List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input"));
    int elementsToSelect = numCards;
    int elementsSelected = 0;
    for (WebElement e : dataIdElements) {
        e.click();
        elementsSelected++;
        if (elementsToSelect == elementsSelected) {
            break;
        }
    }

    switchToFlowButton.click();

    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    //elements = driver.findElements(By.id("influent-flow-rename-file-close"));
    elements = driver.findElements(By.id("influent-flow-rename-file-close"));
    element = SeleniumUtils.getDisplayedElement(elements);
    element.click();

    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    }

    if (expand) {
        elements = driver.findElements(By.className("clipContainer"));
        element = SeleniumUtils.getDisplayedElement(elements);

        element.click();

        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}