From e923c1389b85331d2c98aaeb6bbca88bc57821cd Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 21 Apr 2013 23:53:00 +0400 Subject: [PATCH] Improving overflow handling in isShown atom. A bunch of new tests added for Java binding, but someone should reimplement them in JavaScript too --- common/src/web/overflow/x_auto_y_auto.html | 30 +++++++ common/src/web/overflow/x_auto_y_hidden.html | 30 +++++++ common/src/web/overflow/x_auto_y_scroll.html | 30 +++++++ common/src/web/overflow/x_hidden_y_auto.html | 30 +++++++ .../src/web/overflow/x_hidden_y_hidden.html | 30 +++++++ .../src/web/overflow/x_hidden_y_scroll.html | 30 +++++++ common/src/web/overflow/x_scroll_y_auto.html | 30 +++++++ .../src/web/overflow/x_scroll_y_hidden.html | 30 +++++++ .../src/web/overflow/x_scroll_y_scroll.html | 30 +++++++ .../org/openqa/selenium/VisibilityTest.java | 82 +++++++++++++++++++ javascript/atoms/dom.js | 16 ++-- 11 files changed, 362 insertions(+), 6 deletions(-) create mode 100644 common/src/web/overflow/x_auto_y_auto.html create mode 100644 common/src/web/overflow/x_auto_y_hidden.html create mode 100644 common/src/web/overflow/x_auto_y_scroll.html create mode 100644 common/src/web/overflow/x_hidden_y_auto.html create mode 100644 common/src/web/overflow/x_hidden_y_hidden.html create mode 100644 common/src/web/overflow/x_hidden_y_scroll.html create mode 100644 common/src/web/overflow/x_scroll_y_auto.html create mode 100644 common/src/web/overflow/x_scroll_y_hidden.html create mode 100644 common/src/web/overflow/x_scroll_y_scroll.html diff --git a/common/src/web/overflow/x_auto_y_auto.html b/common/src/web/overflow/x_auto_y_auto.html new file mode 100644 index 0000000000000..cf8a64719436a --- /dev/null +++ b/common/src/web/overflow/x_auto_y_auto.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_auto_y_hidden.html b/common/src/web/overflow/x_auto_y_hidden.html new file mode 100644 index 0000000000000..96fd750a6b4af --- /dev/null +++ b/common/src/web/overflow/x_auto_y_hidden.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_auto_y_scroll.html b/common/src/web/overflow/x_auto_y_scroll.html new file mode 100644 index 0000000000000..6f1d90b6df051 --- /dev/null +++ b/common/src/web/overflow/x_auto_y_scroll.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_hidden_y_auto.html b/common/src/web/overflow/x_hidden_y_auto.html new file mode 100644 index 0000000000000..24dd192830661 --- /dev/null +++ b/common/src/web/overflow/x_hidden_y_auto.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_hidden_y_hidden.html b/common/src/web/overflow/x_hidden_y_hidden.html new file mode 100644 index 0000000000000..cae566578f0bf --- /dev/null +++ b/common/src/web/overflow/x_hidden_y_hidden.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_hidden_y_scroll.html b/common/src/web/overflow/x_hidden_y_scroll.html new file mode 100644 index 0000000000000..d4ffa3970fb56 --- /dev/null +++ b/common/src/web/overflow/x_hidden_y_scroll.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_scroll_y_auto.html b/common/src/web/overflow/x_scroll_y_auto.html new file mode 100644 index 0000000000000..d425a2a8a5efc --- /dev/null +++ b/common/src/web/overflow/x_scroll_y_auto.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_scroll_y_hidden.html b/common/src/web/overflow/x_scroll_y_hidden.html new file mode 100644 index 0000000000000..4a6ff595d3b41 --- /dev/null +++ b/common/src/web/overflow/x_scroll_y_hidden.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/common/src/web/overflow/x_scroll_y_scroll.html b/common/src/web/overflow/x_scroll_y_scroll.html new file mode 100644 index 0000000000000..efa80742ad7e3 --- /dev/null +++ b/common/src/web/overflow/x_scroll_y_scroll.html @@ -0,0 +1,30 @@ + + + + Page with overflow + + + +
+
+
Click right
+
+
+ Right clicked:
+ Bottom clicked:
+ Bottom-right clicked:
+
+
+
Click bottom-right
+
+ Click bottom +
+ + diff --git a/java/client/test/org/openqa/selenium/VisibilityTest.java b/java/client/test/org/openqa/selenium/VisibilityTest.java index ab576792c7d0d..2dad0c8a0a1e4 100644 --- a/java/client/test/org/openqa/selenium/VisibilityTest.java +++ b/java/client/test/org/openqa/selenium/VisibilityTest.java @@ -162,6 +162,88 @@ public void parentNodeVisibleWhenAllChildrenAreAbsolutelyPositionedAndOverflowIs assertTrue(element.isDisplayed()); } + @Test + public void testElementHiddenByOverflowXIsNotVisible() { + String[] pages = new String[]{ + "overflow/x_hidden_y_hidden.html", + "overflow/x_hidden_y_scroll.html", + "overflow/x_hidden_y_auto.html", + }; + for (String page: pages) { + driver.get(appServer.whereIs(page)); + WebElement right = driver.findElement(By.id("right")); + System.out.println(right.getLocation()); + assertFalse(page, right.isDisplayed()); + WebElement bottomRight = driver.findElement(By.id("bottom-right")); + assertFalse(page, bottomRight.isDisplayed()); + } + } + + @Test + public void testElementHiddenByOverflowYIsNotVisible() { + String[] pages = new String[]{ + "overflow/x_hidden_y_hidden.html", + "overflow/x_scroll_y_hidden.html", + "overflow/x_auto_y_hidden.html", + }; + for (String page: pages) { + driver.get(appServer.whereIs(page)); + WebElement bottom = driver.findElement(By.id("bottom")); + assertFalse(page, bottom.isDisplayed()); + WebElement bottomRight = driver.findElement(By.id("bottom-right")); + assertFalse(page, bottomRight.isDisplayed()); + } + } + + @Test + public void testElementScrollableByOverflowXIsVisible() { + String[] pages = new String[]{ + "overflow/x_scroll_y_hidden.html", + "overflow/x_scroll_y_scroll.html", + "overflow/x_scroll_y_auto.html", + "overflow/x_auto_y_hidden.html", + "overflow/x_auto_y_scroll.html", + "overflow/x_auto_y_auto.html", + }; + for (String page: pages) { + driver.get(appServer.whereIs(page)); + WebElement right = driver.findElement(By.id("right")); + assertTrue(page, right.isDisplayed()); + } + } + + @Test + public void testElementScrollableByOverflowYIsVisible() { + String[] pages = new String[]{ + "overflow/x_hidden_y_scroll.html", + "overflow/x_scroll_y_scroll.html", + "overflow/x_auto_y_scroll.html", + "overflow/x_hidden_y_auto.html", + "overflow/x_scroll_y_auto.html", + "overflow/x_auto_y_auto.html", + }; + for (String page: pages) { + driver.get(appServer.whereIs(page)); + WebElement bottom = driver.findElement(By.id("bottom")); + assertTrue(page, bottom.isDisplayed()); + } + } + + @Test + public void testElementScrollableByOverflowXAndYIsVisible() { + String[] pages = new String[]{ + "overflow/x_scroll_y_scroll.html", + "overflow/x_scroll_y_auto.html", + "overflow/x_auto_y_scroll.html", + "overflow/x_auto_y_auto.html", + }; + for (String page: pages) { + driver.get(appServer.whereIs(page)); + WebElement bottomRight = driver.findElement(By.id("bottom-right")); + assertTrue(page, bottomRight.isDisplayed()); + } + } + @Test @Ignore({ANDROID, IPHONE, OPERA, OPERA_MOBILE}) public void tooSmallAWindowWithOverflowHiddenIsNotAProblem() { diff --git a/javascript/atoms/dom.js b/javascript/atoms/dom.js index acdd75d659ce7..fcc527f6bab1f 100644 --- a/javascript/atoms/dom.js +++ b/javascript/atoms/dom.js @@ -728,11 +728,15 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) { // Elements should be hidden if their parent has a fixed size AND has the // style overflow:hidden AND the element's location is not within the fixed // size of the parent - function isOverflowHiding(e) { - var parent = goog.dom.getParentElement(e); + function isOverflowHiding(e, block) { + var parent; + if (block == null) { + parent = goog.dom.getParentElement(e); + } else { + parent = goog.dom.getParentElement(block); + } - if (parent && (bot.dom.getEffectiveStyle(parent, 'overflow') == 'hidden' || - bot.dom.getEffectiveStyle(parent, 'overflow-x') == 'hidden' || + if (parent && (bot.dom.getEffectiveStyle(parent, 'overflow-x') == 'hidden' || bot.dom.getEffectiveStyle(parent, 'overflow-y') == 'hidden')) { var sizeOfParent = bot.dom.getElementSize(parent); var locOfParent = goog.style.getClientPosition(parent); @@ -747,10 +751,10 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) { } return true; } - return !parent || isOverflowHiding(parent); + return !parent || isOverflowHiding(e, parent); } - if (!isOverflowHiding(elem)) { + if (!isOverflowHiding(elem, null)) { return false; }