Search in sources :

Example 56 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project jlineup by otto-de.

the class Browser method takeScreenshotsForContext.

private void takeScreenshotsForContext(final ScreenshotContext screenshotContext) throws Exception {
    boolean headless_chrome_or_firefox = (config.browser == Type.CHROME_HEADLESS || config.browser == Type.FIREFOX_HEADLESS);
    final WebDriver localDriver;
    if (headless_chrome_or_firefox) {
        localDriver = initializeWebDriver(screenshotContext.windowWidth);
    } else
        localDriver = initializeWebDriver();
    if (printVersion.getAndSet(false)) {
        System.out.println("\n\n" + "====================================================\n" + "User agent: " + getBrowserAndVersion() + "\n" + "====================================================\n" + "\n");
    }
    // No need to move the mouse out of the way for headless browsers, but this avoids hovering links in other browsers
    if (config.browser != Type.PHANTOMJS && !headless_chrome_or_firefox) {
        moveMouseToZeroZero();
    }
    if (!headless_chrome_or_firefox) {
        localDriver.manage().window().setPosition(new Point(0, 0));
        resizeBrowser(localDriver, screenshotContext.windowWidth, config.windowHeight);
    }
    final String url = buildUrl(screenshotContext.url, screenshotContext.urlSubPath, screenshotContext.urlConfig.envMapping);
    final String rootUrl = buildUrl(screenshotContext.url, "/", screenshotContext.urlConfig.envMapping);
    if (areThereCookiesOrStorage(screenshotContext)) {
        // get root page from url to be able to set cookies afterwards
        // if you set cookies before getting the page once, it will fail
        LOG.info(String.format("Getting root url: %s to set cookies, local and session storage", rootUrl));
        localDriver.get(rootUrl);
        checkForErrors(localDriver);
        // set cookies and local storage
        setCookies(screenshotContext);
        setLocalStorage(screenshotContext);
        setSessionStorage(screenshotContext);
    }
    if (headless_chrome_or_firefox) {
        browserCacheWarmupForHeadless(screenshotContext, url, localDriver);
    } else {
        checkBrowserCacheWarmup(screenshotContext, url, localDriver);
    }
    // now get the real page
    LOG.info(String.format("Browsing to %s with window size %dx%d", url, screenshotContext.windowWidth, config.windowHeight));
    // Selenium's get() method blocks until the browser/page fires an onload event (files and images referenced in the html have been loaded,
    // but there might be JS calls that load more stuff dynamically afterwards).
    localDriver.get(url);
    checkForErrors(localDriver);
    Long pageHeight = getPageHeight();
    final Long viewportHeight = getViewportHeight();
    if (screenshotContext.urlConfig.waitAfterPageLoad > 0) {
        try {
            LOG.debug(String.format("Waiting for %d seconds (wait-after-page-load)", screenshotContext.urlConfig.waitAfterPageLoad));
            Thread.sleep(screenshotContext.urlConfig.waitAfterPageLoad * 1000);
        } catch (InterruptedException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    if (config.globalWaitAfterPageLoad > 0) {
        LOG.debug(String.format("Waiting for %s seconds (global wait-after-page-load)", config.globalWaitAfterPageLoad));
        Thread.sleep(Math.round(config.globalWaitAfterPageLoad * 1000));
    }
    LOG.debug("Page height before scrolling: {}", pageHeight);
    LOG.debug("Viewport height of browser window: {}", viewportHeight);
    scrollToTop();
    // Execute custom javascript if existing
    executeJavaScript(screenshotContext.urlConfig.javaScript);
    // Wait for fonts
    if (screenshotContext.urlConfig.waitForFontsTime > 0) {
        if (config.browser != Type.PHANTOMJS) {
            WebDriverWait wait = new WebDriverWait(getWebDriver(), screenshotContext.urlConfig.waitForFontsTime);
            wait.until(fontsLoaded);
        } else {
            System.out.println("WARNING: 'wait-for-fonts-time' is ignored because PhantomJS doesn't support this feature.");
        }
    }
    for (int yPosition = 0; yPosition < pageHeight && yPosition <= screenshotContext.urlConfig.maxScrollHeight; yPosition += viewportHeight) {
        BufferedImage currentScreenshot = takeScreenshot();
        currentScreenshot = waitForNoAnimation(screenshotContext, currentScreenshot);
        fileService.writeScreenshot(currentScreenshot, screenshotContext.url, screenshotContext.urlSubPath, screenshotContext.windowWidth, yPosition, screenshotContext.before ? BEFORE : AFTER);
        // This is subject to change because W3C standard wants viewport screenshots
        if (config.browser == Type.PHANTOMJS) {
            break;
        }
        LOG.debug("topOfViewport: {}, pageHeight: {}", yPosition, pageHeight);
        scrollBy(viewportHeight.intValue());
        LOG.debug("Scroll by {} done", viewportHeight.intValue());
        if (screenshotContext.urlConfig.waitAfterScroll > 0) {
            LOG.debug("Waiting for {} seconds (wait after scroll).", screenshotContext.urlConfig.waitAfterScroll);
            TimeUnit.SECONDS.sleep(screenshotContext.urlConfig.waitAfterScroll);
        }
        // Refresh to check if page grows during scrolling
        pageHeight = getPageHeight();
        LOG.debug("Page height is {}", pageHeight);
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Point(org.openqa.selenium.Point) Point(org.openqa.selenium.Point) BufferedImage(java.awt.image.BufferedImage)

Example 57 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project Payara by payara.

the class ElementFinder method findElement.

public WebElement findElement(By locator, int timeout, ExpectedCondition<Boolean> condition) {
    WebDriverWait w = new WebDriverWait(driver, timeout);
    w.until(condition);
    return driver.findElement(locator);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 58 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project webapp by elimu-ai.

the class AjaxHelper method waitForElement.

public static void waitForElement(final By by, final WebDriver webDriver) {
    WebDriverWait webDriverWait = new WebDriverWait(webDriver, TIMOUT_IN_SECONDS);
    webDriverWait.until(ExpectedConditions.presenceOfElementLocated(by));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 59 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project webapp by elimu-ai.

the class AudioEditPage method removeWordLabel.

public void removeWordLabel(String word) {
    int numberOfWordLabelsBefore = driver.findElements(By.cssSelector("#wordLabelContainer > .chip")).size();
    WebElement wordLabel = driver.findElement(By.cssSelector("[data-wordvalue=\"" + word + "\"]"));
    WebElement wordDeleteLink = wordLabel.findElement(By.className("wordDeleteLink"));
    // wordDeleteLink.click();
    // Hack to enable Firefox to click the delete icon
    wordDeleteLink.findElement(By.className("material-icons")).click();
    // Wait for the Ajax call to complete
    WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
    webDriverWait.until(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#wordLabelContainer > .chip"), numberOfWordLabelsBefore - 1));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 60 with WebDriverWait

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

the class ShibbolethTest method testLinkAndSignInWithShibbolethWithoutPersistentId.

@Test
public void testLinkAndSignInWithShibbolethWithoutPersistentId() throws IOException {
    List<Pair<String, String>> headers = new ArrayList<>();
    headers.add(new ImmutablePair<>("Shib-Identity-Provider", "https://integrationtest.orcid.org/idp/shibboleth"));
    webDriver = createFireFoxDriverWithModifyHeaders(headers);
    webDriver.get(baseUri + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUri + "/shibboleth/signin");
    new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[string(.) = 'Sorry! Sign in via your institutional account was unsuccessful.']")));
}
Also used : ArrayList(java.util.ArrayList) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)527 WebElement (org.openqa.selenium.WebElement)166 WebDriver (org.openqa.selenium.WebDriver)131 Test (org.junit.Test)86 By (org.openqa.selenium.By)54 Actions (org.openqa.selenium.interactions.Actions)53 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)43 TimeoutException (org.openqa.selenium.TimeoutException)38 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)36 IOException (java.io.IOException)28 List (java.util.List)26 Wait (org.openqa.selenium.support.ui.Wait)25 BeforeClass (org.junit.BeforeClass)24 NgWebDriver (com.github.sergueik.jprotractor.NgWebDriver)21 ArrayList (java.util.ArrayList)21 WebDriverException (org.openqa.selenium.WebDriverException)21 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)21 Dimension (org.openqa.selenium.Dimension)20 File (java.io.File)16 NoSuchElementException (org.openqa.selenium.NoSuchElementException)16