Search in sources :

Example 6 with Point

use of org.openqa.selenium.Point in project selenium-tests by Wikia.

the class InfoboxBuilderPage method dragAndDropToTheTop.

/**
   _   _                     __     _
   | | | |,^.        ,'.      | `.  | |
   | | |  ,. `.    ,'   `.    | . `.| |
   | | | .--`,'  ,'  ,^.  `.  | |`.   |
   | | | |`. `. `. ,'___`. ,' | |  `| |
   |_| |_|  `. `. `._____,'   |_|   | |
   `/                    `.|
   `
   __               _   _   __         ____  __     _
   | `. ,^.       ,' | | | |  `.      |  __| | `.  | |
   | . ' , |  /`,' . | | | | |`.`.    | |__  | . `.| |
   | |`.'| |  `. ,'| | | | | |  `.`.  |  __| | |`.   |
   | |   | | ,' . `. | | | | |____` / | |__  | |  `| |
   |_|   | | \,' `.__| |_| |_______/   `.__| |_|   | |
   `.|                                       `.|

   Dragging move is actually a 20 small moves, to make is a bit slower
   */
public WebElement dragAndDropToTheTop(WebElement draggedElement) {
    this.wait.forElementClickable(draggedElement);
    WebElement infoboxBackground = driver.findElement(By.cssSelector(".portable-infobox.pi-background"));
    Point location = infoboxBackground.getLocation();
    Integer targetY = draggedElement.getLocation().getY() - location.getY() + 50;
    new Actions(driver).clickAndHold(draggedElement).perform();
    for (int i = 0; i < 20; i++) {
        new Actions(driver).moveByOffset(0, -targetY / 20).perform();
    }
    new Actions(driver).release().perform();
    wait.forValueToBeNotPresentInElementsAttribute(draggedElement, "class", "is-dragging");
    wait.forValueToBeNotPresentInElementsAttribute(draggedElement, "class", "is-dropping");
    return component.get(0);
}
Also used : Actions(org.openqa.selenium.interactions.Actions) Point(org.openqa.selenium.Point) WebElement(org.openqa.selenium.WebElement) Point(org.openqa.selenium.Point)

Example 7 with Point

use of org.openqa.selenium.Point in project selenium-tests by Wikia.

the class AdsSkinHelper method getMiddleColor.

public String getMiddleColor() {
    Point startPoint = new Point((articleLeftSideX + articleRightSideX) / 2, startSkinY + 3);
    File pixel = shooter.capturePageAndCrop(startPoint, new Dimension(1, 1), driver);
    return toHex(new Color(imageEditor.fileToImage(pixel).getRGB(0, 0)));
}
Also used : Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) File(java.io.File)

Example 8 with Point

use of org.openqa.selenium.Point in project selenium-tests by Wikia.

the class AdsSkinHelper method getCutPattern.

private File getCutPattern(BufferedImage patternImage, boolean isLeft) {
    Point startPoint;
    Dimension size;
    if (isLeft) {
        size = new Dimension(articleLeftSideX, patternImage.getHeight());
        startPoint = new Point(patternImage.getWidth() - articleLeftSideX, 0);
    } else {
        size = new Dimension(viewPortWidth - articleRightSideX, patternImage.getHeight());
        startPoint = new Point(0, 0);
    }
    return imageEditor.cropImage(startPoint, size, patternImage);
}
Also used : Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension)

Example 9 with Point

use of org.openqa.selenium.Point 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 10 with Point

use of org.openqa.selenium.Point in project blueocean-plugin by jenkinsci.

the class SmartWebElement method click.

@Override
public void click() {
    for (int i = 0; i < RETRY_COUNT; i++) {
        try {
            WebElement e = getElement();
            e.click();
            if (i > 0) {
                logger.info(String.format("retry click successful for %s", by.toString()));
            }
            return;
        } catch (WebDriverException ex) {
            if (ex.getMessage().contains("is not clickable at point")) {
                logger.warn(String.format("%s not clickable: will retry click", by.toString()));
                logger.debug("exception: " + ex.getMessage());
                try {
                    // typically this is during an animation, which should not take long
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                // ignore
                }
            } else {
                throw ex;
            }
        }
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) Point(org.openqa.selenium.Point) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

Point (org.openqa.selenium.Point)15 Dimension (org.openqa.selenium.Dimension)9 File (java.io.File)4 WebElement (org.openqa.selenium.WebElement)4 BufferedImage (java.awt.image.BufferedImage)2 WebDriver (org.openqa.selenium.WebDriver)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebDriverException (org.openqa.selenium.WebDriverException)1 Actions (org.openqa.selenium.interactions.Actions)1 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1