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 50828202f50..f5b00515f8e 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 @@ -317,6 +317,45 @@ public class PageObject { }); } + /** + *

+ * Finds and returns the first element with the specified selenium id in the given search context. If multiple + * elements exists, the first found element is returned. If no matching element can be found, {@code null} is + * returned. + *

+ * + * @param context + * The search context to use for the search. + * @param id + * The selenium id of the element. + * @return The first matching element in the given context. + */ + protected WebElement findElementOrNullBySeleniumId(SearchContext context, String id) { + final List elements = context.findElements(new BySeleniumId(id)); + WebElement result; + if (elements.isEmpty()) { + result = null; + } else { + result = elements.get(0); + } + return result; + } + + /** + *

+ * Finds and returns the first element with the specified selenium id in the given search context. If multiple + * elements exists, the first found element is returned. If no matching element can be found, {@code null} is + * returned. + *

+ * + * @param id + * The selenium id of the element. + * @return The first matching element in the given context. + */ + protected WebElement findElementOrNullBySeleniumId(String id) { + return findElementOrNullBySeleniumId(this.context, id); + } + /** *

Finds and returns the first element with the specified selenium id in the given search context. If multiple * elements exists, the element closest to the context is returned.

diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayLeaderboardView.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayLeaderboardView.java index a0bae3b1e50..2dfb1fa7fdd 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayLeaderboardView.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayLeaderboardView.java @@ -2,7 +2,9 @@ package com.sap.sailing.selenium.pages.autoplay; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; +import com.google.common.base.Function; import com.sap.sailing.selenium.pages.PageArea; import com.sap.sailing.selenium.pages.leaderboard.LeaderboardTablePO; @@ -12,7 +14,34 @@ public class AutoPlayLeaderboardView extends PageArea { } public LeaderboardTablePO getLeaderBoard() { - return new LeaderboardTablePO(this.driver, waitForElementBySeleniumId(driver, "LeaderboardCellTable", 20)); + WebElement leaderboardCellTable = new WebDriverWait(driver, 30).until(new Function() { + @Override + public WebElement apply(WebDriver driver) { + WebElement leaderboardCellTable = findElementOrNullBySeleniumId("LeaderboardCellTable"); + if (leaderboardCellTable != null) { + try { + if (leaderboardCellTable.isDisplayed()) { + final int windowWidth = driver.manage().window().getSize().getWidth(); + if (windowWidth >= leaderboardCellTable.getLocation().x + + leaderboardCellTable.getSize().width) { + return leaderboardCellTable; + } else { + return null; + } + } else { + return null; + } + } catch (Exception e) { + // The element may currently only partially visible which makes some of the calls fail + // In this case it is necessary to wait for the next loop + return null; + } + } else { + return null; + } + } + }); + return new LeaderboardTablePO(this.driver, leaderboardCellTable); } }