List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:influent.selenium.tests.TransactionsTableTest.java
License:MIT License
@Test public void tableNoResultsTest() { getFlowViewResults("joe", 1, false); //Test a card that has no transactions List<WebElement> elements = driver.findElements(By.className("baseballcardContainer")); WebElement element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: baseballcardContainer element"); }//from w ww . ja v a 2 s.c om 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.id("transactions-table-pagination-label"))); assertEquals("0 results", element.getText()); //check page buttons disabled element = driver.findElement(By.id("transactions-previous-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); element = driver.findElement(By.id("transactions-next-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); }
From source file:influent.selenium.tests.TransactionsTableTest.java
License:MIT License
@Test public void tableMultiResultsOnePageTest() { getFlowViewResults("name:\"joe\" countryCode:\"PE\" datatype:loan matchtype:\"any\"", 2, true); //Test a card that has no transactions List<WebElement> elements = driver.findElements(By.className("baseballcardContainer")); WebElement card1 = null;// ww w. j av a 2s. co m WebElement card2 = null; for (WebElement webElement : elements) { if (webElement.isDisplayed()) { if (card1 == null) { card1 = webElement; } else if (card2 == null) { card2 = webElement; break; } } } if (card1 == null || card2 == null) { throw new AssertionError("Couldn't find: baseballcardContainer element"); } card2.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("transactions-table-pagination-label"))); assertEquals("Showing 1 - 6 of 6", element.getText()); //check page buttons disabled element = driver.findElement(By.id("transactions-previous-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); element = driver.findElement(By.id("transactions-next-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); //check rows element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); assertEquals(6, elements.size()); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("1 2012-11-30 status: paid; repayed: 181.65 (in PEN) - $68.12", element.getText()); //Test highlighting element = card2.findElement(By.cssSelector("[title='highlight flow']")); 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 = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); for (WebElement webElement : elements) { assertEquals(true, webElement.getAttribute("class").contains("transactionsHighlight")); } //Test Export element = driver.findElement(By.id("exportTransactions")); 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.id("dialog-confirm"))); assertEquals("Export successful!", element.getText()); elements = driver.findElements((By.className("ui-button"))); for (WebElement elem : elements) { elem.findElement(By.className("ui-button-text")); if (elem != null && elem.getText().equals("Ok")) { elem.click(); } } try { Thread.sleep(2000); } catch (Exception e) { } //Test table row hyperlinks element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); element = SeleniumUtils.getDisplayedElement(elements); element.click(); element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.className("simpleSearchSummary"))); assertEquals("Showing 1 - 5 of 5 results", element.getText()); }
From source file:influent.selenium.tests.TransactionsTableTest.java
License:MIT License
@Test public void tableMultiResultsMultiPageTest() { /////////////////////////////////////////////////////////////// //Set Up: Select a card that has 100+ transactions where we can //highlight some of those rows. /////////////////////////////////////////////////////////////// getFlowViewResults("name:\"joe\" countryCode:\"PE\" datatype:loan matchtype:\"any\"", 1, false); List<WebElement> elements = driver.findElements(By.className("baseballcardContainer")); WebElement card1 = null;/*from w ww . j av a 2 s . c om*/ for (WebElement webElement : elements) { if (webElement.isDisplayed()) { if (card1 == null) { card1 = webElement; break; } } } if (card1 == null) { throw new AssertionError("Couldn't find: baseballcardContainer element"); } //Click card so add to file buttons appear 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.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("baseballcardContainer")); //WebElement card1 = null; WebElement lender = null; int x = 0; for (WebElement webElement : elements) { if (webElement.getLocation().getX() > x) { x = webElement.getLocation().getX(); lender = webElement; } } lender.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) { } /////////////////////////////////////////////////////////////// //We should now have a transactions table with 100 transactions /////////////////////////////////////////////////////////////// //Check results summary label element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.id("transactions-table-pagination-label"))); assertEquals("Showing 1 - 100 of 111", element.getText()); //check previous buttons disabled element = driver.findElement(By.id("transactions-previous-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); //check previous buttons enabled element = driver.findElement(By.id("transactions-next-page")); assertEquals("btn btn-default", element.getAttribute("class")); //check rows element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); assertEquals(100, elements.size()); //test next button element = driver.findElement(By.id("transactions-next-page")); element.click(); //Wait a few seconds for new table to load. We can't use ExpectedConditions.presenceOfElementLocated since they are already present try { Thread.sleep(2000); } catch (Exception e) { } //Check results summary label element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.id("transactions-table-pagination-label"))); assertEquals("Showing 101 - 111 of 111", element.getText()); //check previous buttons enabled element = driver.findElement(By.id("transactions-previous-page")); assertEquals("btn btn-default", element.getAttribute("class")); //check previous buttons disabled element = driver.findElement(By.id("transactions-next-page")); assertEquals("btn btn-default disabled", element.getAttribute("class")); //check rows element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); assertEquals(11, elements.size()); /////////////////////////////////////////////////////////////// //Test highlighting /////////////////////////////////////////////////////////////// //Setup //find card again element = driver.findElement(By.className("file")); card1 = element.findElement(By.className("baseballcardContainer")); //Click card again so branch right button appears 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) { } element = card1.findElement(By.cssSelector("[title='highlight flow']")); 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 lender again elements = driver.findElements(By.className("baseballcardContainer")); //WebElement card1 = null; lender = null; x = 0; for (WebElement webElement : elements) { if (webElement.getLocation().getX() > x) { x = webElement.getLocation().getX(); lender = webElement; } } lender.click(); //Wait a few seconds for new table to load. We can't use ExpectedConditions.presenceOfElementLocated since they are already present try { Thread.sleep(2000); } catch (Exception e) { } //We should now have transactions from card2 highlighted in lender's transactions table //Check we have the correct number of highlighted rows element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); int highlightCount = 0; for (WebElement webElement : elements) { if (webElement.getAttribute("class") != null && webElement.getAttribute("class").length() >= 21 && webElement.getAttribute("class").substring(0, 21).equals("transactionsHighlight")) { highlightCount++; } } assertEquals(5, highlightCount); //Check the first highlighted row is correct element = element.findElement(By.className("transactionsHighlight-0")); assertEquals("31 2012-11-30 status: paid; repayed: 181.65 (in PEN) $68.12 -", element.getText()); //Test highlighting on next page element = driver.findElement(By.id("transactions-next-page")); element.click(); //Wait a few seconds for new table to load. We can't use ExpectedConditions.presenceOfElementLocated since they are already present try { Thread.sleep(2000); } catch (Exception e) { } //Check we have the correct number of highlighted rows element = driver.findElement(By.id("transactions-table-body")); elements = element.findElements(By.tagName("tr")); highlightCount = 0; for (WebElement webElement : elements) { if (webElement.getAttribute("class") != null && webElement.getAttribute("class").length() >= 21 && webElement.getAttribute("class").substring(0, 21).equals("transactionsHighlight")) { highlightCount++; } } assertEquals(1, highlightCount); //Check the first highlighted row is correct element = element.findElement(By.className("transactionsHighlight-1")); assertEquals("104 2012-05-29 status: paid; loan: 1k (in PEN) - $375.00", element.getText()); }
From source file:influent.selenium.tests.TransactionsTableTest.java
License:MIT License
@Test public void transactionsViewButtonTest() { getFlowViewResults("name:\"joe\" countryCode:\"PE\" datatype:loan matchtype:\"any\"", 1, false); //Test a card that has no transactions List<WebElement> elements = driver.findElements(By.className("baseballcardContainer")); WebElement card1 = null;/*from w w w. j av a 2s .co m*/ for (WebElement webElement : elements) { if (webElement.isDisplayed()) { if (card1 == null) { card1 = webElement; } } } 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("transactions-table-pagination-label"))); element = driver.findElement(By.id("transactions-button")); element.click(); try { Thread.sleep(2000); } catch (Exception e) { } element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.className("simpleSearchSummary"))); assertEquals("Showing 1 - 6 of 6 results", element.getText()); try { Thread.sleep(2000); } catch (Exception e) { } elements = driver.findElements(By.className("simpleSearchResultText")); element = SeleniumUtils.getDisplayedElement(elements); element = element.findElement(By.className("simpleSearchResultFieldValue")); assertEquals("To: a.partner.p71-438363 From: a.loan.b438363", element.getText()); }
From source file:influent.selenium.tests.TransactionsViewTests.java
License:MIT License
@Test public void searchTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_TRANSACTIONS); WebElement resultsRoot = driver.findElement(By.cssSelector("#infLinkSearchResultContainer")); 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 .co m*/ element.sendKeys("from:a.loan.b146773"); 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.className("simpleSearchSummary"))); assertEquals("Showing 1 - 10 of 10 results", element.getText()); element = resultsRoot.findElement((By.className("simpleSearchResultText"))); element = element.findElement(By.className("simpleSearchResultFieldValue")); assertEquals(true, element.getText().length() > 0); elements = resultsRoot.findElements((By.className("infSearchResultStateToggle"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); assertEquals("[less]", element.getText()); //TODO: For Walker we should test new contents after clicking 'more' link // Test selection List<WebElement> switchViewButtons = resultsRoot .findElements(By.cssSelector("#infLinkSearchResultOpBar [switchesto]")); WebElement switchToAccountsButton = null; for (WebElement e : switchViewButtons) { String switchTo = e.getAttribute("switchesto"); if (switchTo.equals(SeleniumUtils.ACCOUNTS_NAME)) { switchToAccountsButton = e; break; } } if (switchToAccountsButton == null) { throw new AssertionError("Couldn't find: Button to switch to accounts view in infOperationsBar"); } elements = resultsRoot.findElements((By.cssSelector(".selectSingleResult input"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); switchToAccountsButton.click(); WebElement firstAccountsResult = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".selectSingleResult"))); if (firstAccountsResult == null) { throw new AssertionError( "Couldn't find any accounts results. Either timed out or search returned no entities!"); } elements = driver .findElements((By.cssSelector("#infAccountSearchResultContainer .simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals( "Name:DanielDescription:Daniel R. O. is 34 years old and lives in the department of La Libertad with his wife and their 3 children (ages 16, 13, and 4). Daniels wife works as a traveling merchant and helps with the household expenses. In turn, Daniel has a business in the central market selling fruits and vegetables. He has been ...", element.getText()); elements = driver.findElements((By.cssSelector(".selectSingleResult input[type='checkbox']"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); elements = driver.findElements((By.className("searchResultSelected"))); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Selected result was not highlighted"); } }
From source file:influent.selenium.tests.TransactionsViewTests.java
License:MIT License
@Test public void fromLinkTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_TRANSACTIONS); WebElement resultsRoot = driver.findElement(By.cssSelector("#infLinkSearchResultContainer")); 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 a2 s .c o m element.sendKeys("from:a.null.b146773"); 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.className("simpleSearchSummary"))); assertEquals("Showing 1 - 10 of 10 results", element.getText()); elements = resultsRoot.findElements((By.className("summaryColumnFROM_ID"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); WebElement firstAccountsResult = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".selectSingleResult"))); if (firstAccountsResult == null) { throw new AssertionError( "Couldn't find any accounts results. Either timed out or search returned no entities!"); } elements = driver .findElements((By.cssSelector("#infAccountSearchResultContainer .simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals( "Name:DanielDescription:Daniel R. O. is 34 years old and lives in the department of La Libertad with his wife and their 3 children (ages 16, 13, and 4). Daniels wife works as a traveling merchant and helps with the household expenses. In turn, Daniel has a business in the central market selling fruits and vegetables. He has been ...", element.getText()); }
From source file:influent.selenium.tests.TransactionsViewTests.java
License:MIT License
@Test public void toLinkTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_TRANSACTIONS); WebElement resultsRoot = driver.findElement(By.cssSelector("#infLinkSearchResultContainer")); 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 2s. co m element.sendKeys("from:a.null.b146773"); 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.className("simpleSearchSummary"))); assertEquals("Showing 1 - 10 of 10 results", element.getText()); elements = resultsRoot.findElements((By.className("summaryColumnTO_ID"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); WebElement firstAccountsResult = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".selectSingleResult"))); if (firstAccountsResult == null) { throw new AssertionError( "Couldn't find any accounts results. Either timed out or search returned no entities!"); } elements = driver .findElements((By.cssSelector("#infAccountSearchResultContainer .simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("Name:Apoyo IntegralStatus:activeDue Diligence Type:Full", element.getText()); }
From source file:io.federecio.dropwizard.swagger.selenium.DefaultServerWithCustomTemplateSeleniumTest.java
License:Apache License
@Test public void testCustomLogo() throws Exception { driver.get(getSwaggerUrl());/* w w w. j a va 2s . co m*/ driver.manage().timeouts().implicitlyWait(WAIT_IN_SECONDS, TimeUnit.SECONDS); // Check for custom logo in the template By inputSelector = By.xpath("//img[@class=\"logo__img\"]"); new WebDriverWait(driver, WAIT_IN_SECONDS) .until(ExpectedConditions.presenceOfElementLocated(inputSelector)); new WebDriverWait(driver, WAIT_IN_SECONDS) .until(ExpectedConditions.attributeContains(inputSelector, "src", "myassets/dropwizard-logo.png")); }
From source file:io.federecio.dropwizard.swagger.selenium.SeleniumTest.java
License:Apache License
private void clickOnTryOut() { By xpath = By.xpath("//input[@value='Try it out!']"); new WebDriverWait(driver, WAIT_IN_SECONDS).until(ExpectedConditions.presenceOfElementLocated(xpath)); driver.findElement(xpath).click();// w w w . jav a2 s .com }
From source file:io.github.bonigarcia.wdm.base.BaseBrowserTst.java
License:Open Source License
@Test public void test() { if (validOS) { WebDriverWait wait = new WebDriverWait(driver, TIMEOUT); driver.get("https://en.wikipedia.org/wiki/Main_Page"); By searchInput = By.id("searchInput"); wait.until(ExpectedConditions.presenceOfElementLocated(searchInput)); driver.findElement(searchInput).sendKeys("Software"); By searchButton = By.id("searchButton"); wait.until(ExpectedConditions.elementToBeClickable(searchButton)); driver.findElement(searchButton).click(); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); }// w w w . j a va 2 s . c om }