From 67a01d6a69a0088cff46ddf0b758146e1d22ecac Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Tue, 24 Apr 2018 16:55:40 +0200 Subject: [PATCH] Bug 4339: Due to the WebDriver specification, moveTo or click are not expected to scroll the element into view. This can lead to test failures depending on the WebDriver implementation (e.g. GeckoDriver). This change explicitly ensures at some central places that elements to be clicked are being scrolled into view. --- .../sailing/selenium/pages/PageObject.java | 10 +++++++ .../pages/common/DataEntryDialogPO.java | 2 +- .../selenium/pages/gwt/DataEntryPO.java | 27 +++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/PageObject.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/PageObject.java index f29bcfbcb84..e8a85ce67d5 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/PageObject.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/PageObject.java @@ -12,6 +12,7 @@ import java.util.logging.Logger; import org.openqa.selenium.Alert; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.NoAlertPresentException; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebDriver; @@ -585,4 +586,13 @@ public class PageObject { } throw new NoAlertPresentException(); } + + protected void scrollToView(WebElement webElement) { + ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", webElement); + } + + protected void scrollToViewAndClick(WebElement webElement) { + scrollToView(webElement); + webElement.click(); + } } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/common/DataEntryDialogPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/common/DataEntryDialogPO.java index 69e12386513..6fed4c53712 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/common/DataEntryDialogPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/common/DataEntryDialogPO.java @@ -57,7 +57,7 @@ public abstract class DataEntryDialogPO extends PageArea { } public void pressOk(boolean accept) { - this.okButton.click(); + scrollToViewAndClick(this.okButton); ExpectedCondition condition = ExpectedConditions.alertIsPresent(); Alert alert = condition.apply(this.driver); diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java index be0fc963101..a602218b34a 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java @@ -119,17 +119,34 @@ public class DataEntryPO extends CellTableRowPO { protected Action getModifiedSelectAction() { Actions actions = new Actions(this.driver); + final WebElement elementToSelect; + final boolean controlClick; if (table.getColumnHeaders().get(0).equals("\u2713")) { // it's a checkbox column - actions.moveToElement(this.columns.isEmpty() ? getWebElement() : this.columns.get(0)); - actions.click(); + elementToSelect = this.columns.isEmpty() ? getWebElement() : this.columns.get(0); + controlClick = false; } else { + elementToSelect = getElementForSelect(); + controlClick = true; + } + if (controlClick) { actions.keyDown(Keys.CONTROL); - moveToUpperLeftCorner(actions, getElementForSelect()); - actions.click(); + } + moveToUpperLeftCorner(actions, elementToSelect); + actions.moveToElement(elementToSelect, 1, 1); + actions.click(); + if (controlClick) { actions.keyUp(Keys.CONTROL); } - return actions.build(); + final CompositeAction compositeAction = new CompositeAction(); + compositeAction.addAction(new Action() { + @Override + public void perform() { + scrollToView(elementToSelect); + } + }); + compositeAction.addAction(actions.build()); + return compositeAction; } protected CompositeAction getModifiedCompositeActionAction() {