Search in sources :

Example 21 with ExpectedCondition

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

the class Waiter method waitForUrl.

/**
 * Wait for a URL to open in the browser and for the page to load completely.
 * Wait for the specifiedTimeout number of seconds.
 *
 * @param url              - the URL to open
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForUrl(String url, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> urlIsCorrect = arg0 -> driver.getCurrentUrl().equals(url);
    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)

Example 22 with ExpectedCondition

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

the class Waiter method waitForUrlStartsWith.

/**
 * Wait for the URL in the browser to start with a specified String.
 * Please see the startsWith method from the String class for details on how this method determines whether a
 * String starts with another one.
 * Wait for the specifiedTimeout number of seconds.
 *
 * @param expectedString   - the expected String to be found at the start of the URL loaded in the browser
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForUrlStartsWith(String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> urlIsCorrect = arg0 -> driver.getCurrentUrl().startsWith(expectedString);
    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)

Example 23 with ExpectedCondition

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

the class Waiter method waitForElementToBeDisplayed.

/**
 * Method that waits for the Selenium isDisplayed() method to return true.
 * Hence waits for an element to be displayed.
 * Will wait for up to the specified amount of seconds.
 *
 * @param element          - the WebElement to be displayed
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementToBeDisplayed(WebElement element, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementIsDisplayed = arg0 -> element.isDisplayed();
    wait.until(elementIsDisplayed);
}
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 24 with ExpectedCondition

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

the class Waiter method waitForElementAttributeEqualsString_IgnoreWhitespaces.

/**
 * Method that waits for an element's attribute value (whose whitespaces are removed) to equal an expected
 * String (whose whitespaces are also removed).
 * Basically, does a getAttribute(nameOfAttribute) on the WebElement, removes all whitespaces from this resulting
 * String, then compares this value to another String that contains no whitespaces.
 * When calling the method, the expectedString can contain whitespaces, as they are removed inside this method.
 * Whitespaces include: space, new line, tab.
 * Having said that, only the non whitespace characters are compared.
 * Therefore, 'this      string  here' will equal 'this string here'.
 * Will wait for up to the specified timeout number of seconds for expected condition to occur.
 *
 * @param element          - the WebElement whose attribute will be verified
 * @param attribute        - the attribute whose value will be verified
 * @param expectedString   - the expected value of the WebElement's attribute on which a whitespace removal is also
 *                         done
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - the amount of seconds to wait for the condition to occur
 */
public void waitForElementAttributeEqualsString_IgnoreWhitespaces(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementAttributeEqualsStringIW = arg0 -> element.getAttribute(attribute).replaceAll("\\s", "").equals(expectedString.replaceAll("\\s", ""));
    wait.until(elementAttributeEqualsStringIW);
}
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 25 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project chrome_page_performance_sqlite_java by sergueik.

the class ChromePagePerformanceObjectTest method beforeMethod.

@Before
public void beforeMethod() throws IOException {
    driver.get(baseURL);
    // Wait for page url to update
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.pollingEvery(500, TimeUnit.MILLISECONDS);
    ExpectedCondition<Boolean> urlChange = driver -> driver.getCurrentUrl().matches(String.format("^%s.*", baseURL));
    wait.until(urlChange);
    System.err.println("Current  URL: " + driver.getCurrentUrl());
/*
		// Take screenshot
		// under headless Chrome, some vendor pages behave differently e.g.
		// www.royalcaribbean.com redirects to the
		// "Oops... Looks like RoyalCaribbean.com is on vacation" page
		File screenShot = ((TakesScreenshot) driver)
				.getScreenshotAs(OutputType.FILE);
		
		// To get the width of image.
		BufferedImage readImage = ImageIO.read(screenShot);
		int width = readImage.getWidth();
		FileUtils.copyFile(screenShot, new File(System.getProperty("user.dir")
				+ System.getProperty("file.separator") + "test.png"));
		 */
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Arrays(java.util.Arrays) Connection(java.sql.Connection) BeforeClass(org.junit.BeforeClass) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) DatabaseMetaData(java.sql.DatabaseMetaData) HashMap(java.util.HashMap) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ArrayList(java.util.ArrayList) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) CapabilityType(org.openqa.selenium.remote.CapabilityType) SQLException(java.sql.SQLException) Matcher(java.util.regex.Matcher) Map(java.util.Map) After(org.junit.After) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) AfterClass(org.junit.AfterClass) By(org.openqa.selenium.By) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) PreparedStatement(java.sql.PreparedStatement) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Ignore(org.junit.Ignore) Pattern(java.util.regex.Pattern) DriverManager(java.sql.DriverManager) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Before(org.junit.Before)

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