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 a8e2c434d80..35ceb7c7b56 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 @@ -634,4 +634,23 @@ public class PageObject { scrollToView(webElement); webElement.click(); } + + public boolean isElementEntirelyVisible(WebElement element) { + try { + if (element.isDisplayed()) { + final int windowWidth = driver.manage().window().getSize().getWidth(); + if (windowWidth >= element.getLocation().x + + element.getSize().width) { + return true; + } else { + return false; + } + } else { + return false; + } + } catch (Exception e) { + // The element may currently only partially visible which makes some of the calls fail + return false; + } + } } 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 520fea6cc99..39fb7e3926a 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 @@ -14,17 +14,13 @@ public class AutoPlayLeaderboardView extends PageArea { super(driver, element); } - public LeaderboardTablePO getLeaderBoard() { + public LeaderboardTablePO getLeaderBoardWithData() { 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) { + if (isElementEntirelyVisible(leaderboardCellTable)) { return leaderboardCellTable; } else { return null; @@ -32,17 +28,19 @@ public class AutoPlayLeaderboardView extends PageArea { } 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; - } + }); + LeaderboardTablePO leaderboardTablePO = new LeaderboardTablePO(this.driver, leaderboardCellTable); + leaderboardTablePO.waitForTableToShowData(); + + // After the data is loaded it could be possible that the table isn't completely visible anymore + new WebDriverWait(driver, 30).until(new Function() { + @Override + public Boolean apply(WebDriver arg0) { + return isElementEntirelyVisible(leaderboardCellTable); } }); - return new LeaderboardTablePO(this.driver, leaderboardCellTable); + return leaderboardTablePO; } } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java index 504c3020a09..596a2e46a5d 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java @@ -11,7 +11,9 @@ import java.util.stream.Stream; import org.openqa.selenium.By; 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.common.CSSConstants; @@ -343,4 +345,13 @@ public abstract class CellTablePO extends PageArea { return LOADING_ANIMATION_IMAGE.equals(image); } + + public void waitForTableToShowData() { + new WebDriverWait(driver, 30).until(new Function() { + @Override + public Boolean apply(WebDriver driver) { + return !getRows().isEmpty(); + } + }); + } } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/leaderboard/LeaderboardTablePO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/leaderboard/LeaderboardTablePO.java index 087da5c176f..6adaeb9ec78 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/leaderboard/LeaderboardTablePO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/leaderboard/LeaderboardTablePO.java @@ -2,13 +2,11 @@ package com.sap.sailing.selenium.pages.leaderboard; import java.util.ArrayList; import java.util.List; -import java.util.function.Function; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.WebDriverWait; import com.sap.sailing.selenium.pages.common.CSSHelper; import com.sap.sailing.selenium.pages.gwt.CellTablePO; @@ -193,13 +191,4 @@ public class LeaderboardTablePO extends CellTablePO { private WebElement getExpansionButton(WebElement header) { return header.findElement(By.xpath(EXPANSION_BUTTON_XPATH)); } - - public void waitForLeaderboardToHaveData() { - new WebDriverWait(driver, 30).until(new Function() { - @Override - public Boolean apply(WebDriver driver) { - return !getRows().isEmpty(); - } - }); - } } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/autoplay/TestAutoPlay.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/autoplay/TestAutoPlay.java index 52db4e94fde..f79a99f3baf 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/autoplay/TestAutoPlay.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/autoplay/TestAutoPlay.java @@ -117,8 +117,7 @@ public class TestAutoPlay extends AbstractSeleniumTest { assertTrue("Url does not contain proper title " + url, url.contains("lbwh.saph.title=Leaderboard%3A+BMW+Cup+(J80)")); assertTrue("Url does not contain proper name " + url, url.contains("name=BMW+Cup+(J80)")); AutoPlayLeaderboardView autoplayPage = page.goToAutoPlayClassicUrl(getWebDriver(), url); - LeaderboardTablePO leaderBoard = autoplayPage.getLeaderBoard(); - leaderBoard.waitForLeaderboardToHaveData(); + LeaderboardTablePO leaderBoard = autoplayPage.getLeaderBoardWithData(); List races = leaderBoard.getRaceNames(); Assert.assertTrue(races.contains("R1")); Assert.assertTrue(races.contains("R2"));