Search in sources :

Example 26 with ExpectedCondition

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

the class ChromePagePerformanceUtilTest method testnavigateBaseURL.

// @Ignore
@Test
public void testnavigateBaseURL() {
    System.err.println("base URL loading test");
    try {
        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());
    } catch (TimeoutException e) {
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) LogEntry(org.openqa.selenium.logging.LogEntry) BeforeClass(org.junit.BeforeClass) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) HashMap(java.util.HashMap) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Level(java.util.logging.Level) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) CapabilityType(org.openqa.selenium.remote.CapabilityType) JSONObject(org.json.JSONObject) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) LogType(org.openqa.selenium.logging.LogType) Map(java.util.Map) After(org.junit.After) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) LogEntries(org.openqa.selenium.logging.LogEntries) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 27 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project ats-framework by Axway.

the class AbstractRealBrowserDriver method waitForPageLoaded.

public void waitForPageLoaded(WebDriver driver, int timeoutInSeconds) {
    /*InternetExplorer is unable to wait for document's readyState to be complete.*/
    if (this instanceof com.axway.ats.uiengine.InternetExplorerDriver) {
        return;
    }
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {
            return "complete".equals(((JavascriptExecutor) driver).executeScript("return document.readyState"));
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(driver, timeoutInSeconds);
    try {
        wait.until(expectation);
    } catch (Exception e) {
        throw new SeleniumOperationException("Timeout waiting for Page Load Request to complete.", e);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException)

Example 28 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project ats-framework by Axway.

the class AbstractHtmlEngine method switchToWindowByTitle.

private void switchToWindowByTitle(final String windowTitle, long timeoutInSeconds) {
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {
            return switchToWindowByTitle(windowTitle);
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(webDriver, timeoutInSeconds);
    try {
        wait.until(expectation);
    } catch (Exception e) {
        throw new SeleniumOperationException("Timeout waiting for Window with title '" + windowTitle + "' to appear.", e);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 29 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project geode by apache.

the class PulseTestUtils method waitForElement.

public static WebElement waitForElement(By by) {
    WebElement element = (new WebDriverWait(driverProvider.get(), maxWaitTime)).until((ExpectedCondition<WebElement>) d -> d.findElement(by));
    assertNotNull(element);
    return element;
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) HashMap(java.util.HashMap) Region(org.apache.geode.tools.pulse.tests.Region) Supplier(java.util.function.Supplier) JMXProperties(org.apache.geode.tools.pulse.tests.JMXProperties) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) Member(org.apache.geode.tools.pulse.tests.Member) List(java.util.List) TreeMap(java.util.TreeMap) PulseTestLocators(org.apache.geode.tools.pulse.tests.PulseTestLocators) Map(java.util.Map) PulseTestData(org.apache.geode.tools.pulse.tests.PulseTestData) Assert(org.junit.Assert) Actions(org.openqa.selenium.interactions.Actions) Collections(java.util.Collections) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 30 with ExpectedCondition

use of org.openqa.selenium.support.ui.ExpectedCondition in project ORCID-Source by ORCID.

the class OauthAuthorizationPageHelper method authorizeOnAlreadyLoggedInUser.

public static String authorizeOnAlreadyLoggedInUser(final WebDriver loggedInDriver, String baseUrl, String clientId, String redirectUri, String scopes, String stateParam) {
    String formattedAuthorizationScreen = String.format(authorizationScreenUrl, baseUrl, clientId, scopes, redirectUri);
    if (!PojoUtil.isEmpty(stateParam)) {
        formattedAuthorizationScreen += "&state=" + stateParam;
    }
    loggedInDriver.get(formattedAuthorizationScreen);
    try {
        BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfElementLocated(By.xpath("//p[contains(text(),'has asked for the following access to your ORCID Record')]")), loggedInDriver);
        By authorizeElementLocator = By.id("authorize");
        (new WebDriverWait(loggedInDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(authorizeElementLocator));
        WebElement authorizeButton = loggedInDriver.findElement(By.id("authorize"));
        authorizeButton.click();
        (new WebDriverWait(loggedInDriver, BBBUtil.TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver d) {
                return d.getTitle().equals("ORCID Playground");
            }
        });
    } catch (TimeoutException e) {
        // It might be the case that we are already in the ORCID Playground page, so, lets check for that case
        (new WebDriverWait(loggedInDriver, BBBUtil.TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver d) {
                return d.getTitle().equals("ORCID Playground");
            }
        });
    }
    String result = loggedInDriver.getCurrentUrl();
    return result;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) By(org.openqa.selenium.By) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException)

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