Skip to content

Commit

Permalink
[JENKINS-34411] Add overflow override.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Rodriguez committed Apr 29, 2016
1 parent 254d015 commit bf4ecc5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/selenium/Scroller.java
@@ -1,5 +1,7 @@
package org.jenkinsci.test.acceptance.selenium;

import org.apache.commons.io.IOUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -66,19 +68,48 @@ public class Scroller extends AbstractWebDriverEventListener {
/** Vertical margin to use when scrolling to the element. */
private static final int MARGIN_Y = Integer.getInteger("SCROLL_MARGIN_Y", 200);

private final String overflowJS;

public Scroller() throws IOException {
overflowJS = IOUtils.toString(Scroller.class.getResourceAsStream("overflow.js"));
}

@Override
public void beforeClickOn(WebElement element, WebDriver driver) {
scrollIntoView(element, driver);
}

@Override
public void afterClickOn(WebElement element, WebDriver driver) {
// A click can cause a page change.
overideOverflow(driver);
}

@Override
public void beforeChangeValueOf(WebElement element, WebDriver driver) {
scrollIntoView(element, driver);
}

@Override
public void afterNavigateTo(String url, WebDriver driver) {
overideOverflow(driver);
}

@Override
public void afterNavigateBack(WebDriver driver) {
overideOverflow(driver);
}

@Override
public void afterNavigateForward(WebDriver driver) {
overideOverflow(driver);
}

@Override
public void afterNavigateRefresh(WebDriver driver) {
overideOverflow(driver);
}

/**
* To scroll the element to the view, we scroll the element to the top-edge of the screen.
* A (configurable) margin is left to account for decorations.
Expand All @@ -94,4 +125,11 @@ private void scrollIntoView(WebElement e, WebDriver driver) {
final String script = String.format("window.scrollTo(%d, %d);", p.getX() - MARGIN_X, p.getY() - MARGIN_Y);
((JavascriptExecutor)driver).executeScript(script);
}

/** Override overflow behavior (if not done previously). */
private void overideOverflow(WebDriver driver) {
if (driver.findElements(By.id("ath-overflow-override")).isEmpty()) {
((JavascriptExecutor)driver).executeScript(overflowJS);
}
}
}
@@ -0,0 +1,13 @@
var css = '* { overflow: visible !important }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');

style.type = 'text/css';
style.id = 'ath-overflow-override'
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}

head.appendChild(style);

0 comments on commit bf4ecc5

Please sign in to comment.