Search in sources :

Example 36 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project thewaiter by iamalittletester.

the class Waiter method waitForElementTextEqualsString_IgnoreWhitespaces.

/**
 * Method that waits for the text on the element (whose
 * whitespaces are removed) to equal an expected String (whose whitespaces are also removed).
 * Basically, does a getText() on the WebElement, removes all whitespaces from this resulting String, then compares
 * this value to another String that contains no whitespaces.
 * Whitespaces include: space, new line, tab.
 * When calling the method, the expectedString can contain whitespaces, as they are removed inside this method.
 * Therefore, 'this      string  here' will equal 'this string here'.
 * Will wait for up to the specifiedTimeout number of seconds for the text on the element to be the expected one.
 *
 * @param element          - the WebElement whose text will be compared to an expected value after removing the
 *                         whitespaces on this text
 * @param expectedString   - the expected value of the WebElement's text on which a whitespace removal is also done
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementTextEqualsString_IgnoreWhitespaces(WebElement element, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementTextEqualsString = arg0 -> element.getText().replaceAll("\\s", "").equals(expectedString.replaceAll("\\s", ""));
    wait.until(elementTextEqualsString);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 37 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project thewaiter by iamalittletester.

the class Waiter method waitForElementTextEqualsString_IgnoreCase.

/**
 * Method that waits for the text on the element to equal an
 * expected String but ignoring the case of the two.
 * Compares the value resulted from getText() on the element with the expected String, but without taking into
 * account the case of the two values.
 * Therefore, for example 'tHis' and 'This' will be equal when calling this method.
 * Will wait for up to the specifiedTimeout number of seconds for the text on the element to be the expected one.
 *
 * @param element          - the WebElement whose text will be compared to an expected value
 * @param expectedString   - the expected value of the WebElement's text
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementTextEqualsString_IgnoreCase(WebElement element, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementTextEqualsStringIgnoreCase = arg0 -> element.getText().equalsIgnoreCase(expectedString);
    wait.until(elementTextEqualsStringIgnoreCase);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 38 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project thewaiter by iamalittletester.

the class Waiter method waitForElementTextContainsString_IgnoreCase.

/**
 * Method that then waits for the text on the element to contain an
 * expected String but ignoring the case of the two.
 * Checks whether the value resulted from getText() on the element contains the expected String, but without taking
 * into account the case of the two values.
 * Therefore, for example 'tHis' will contain 'his'.
 * Will wait for up to the specifiedTimeout number of seconds for the text on the element to be the expected one.
 *
 * @param element          - the WebElement whose text will be checked
 * @param expectedString   - the value expected to be part of the WebElement's text, ignoring the case
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementTextContainsString_IgnoreCase(WebElement element, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementTextContainsString = arg0 -> element.getText().toLowerCase().contains(expectedString.toLowerCase());
    wait.until(elementTextContainsString);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 39 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project thewaiter by iamalittletester.

the class Waiter method waitForElementAttributeContainsString.

/**
 * Method that waits for an element's specified attribute's value to contain another specified String.
 * Compares the value resulted from getAttribute(nameOfAttribute) on the element with the expected String.
 * Will wait for up to the specified number of seconds for the condition to occur.
 *
 * @param element          - the WebElement whose attribute we are interested in
 * @param attribute        - the attribute whose value needs to be compared to another value
 * @param expectedString   - the expected value of the WebElement's attribute
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementAttributeContainsString(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementAttributeContainsString = arg0 -> element.getAttribute(attribute).contains(expectedString);
    wait.until(elementAttributeContainsString);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 40 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project thewaiter by iamalittletester.

the class Waiter method waitForUrl_IgnoreCase.

/**
 * Wait for an expected URL to load in the browser, but ignore the case of the url.
 * Compares a lower case value of the actual url in the browser with the lower case value of the expected url.
 * Wait for the specifiedTimeout number of seconds.
 *
 * @param url              - the url expected to load in the browser, ignoring its case
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForUrl_IgnoreCase(String url, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> urlIsCorrect = arg0 -> driver.getCurrentUrl().toLowerCase().equals(url.toLowerCase());
    wait.until(urlIsCorrect);
    waitForPageLoadComplete(driver, specifiedTimeout);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Aggregations

ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)57 WebDriver (org.openqa.selenium.WebDriver)54 WebElement (org.openqa.selenium.WebElement)45 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)44 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)31 By (org.openqa.selenium.By)19 Wait (org.openqa.selenium.support.ui.Wait)19 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 List (java.util.List)15 WebDriverException (org.openqa.selenium.WebDriverException)15 Test (org.testng.annotations.Test)15 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 Map (java.util.Map)13 ExpectedConditions (org.openqa.selenium.support.ui.ExpectedConditions)12 AfterMethod (org.testng.annotations.AfterMethod)12 ArrayList (java.util.ArrayList)11 Iterator (java.util.Iterator)11 Optional (java.util.Optional)11