From 1b9a6cdc51c43fb9d78f9c1be46fdbc583466aae Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Fri, 20 Jul 2018 13:00:36 +0200 Subject: [PATCH 1/2] Bug 4675: Waiting for table data is useful for other tests too --- .../sap/sailing/selenium/pages/gwt/CellTablePO.java | 11 +++++++++++ .../pages/leaderboard/LeaderboardTablePO.java | 13 ------------- .../selenium/test/autoplay/TestAutoPlay.java | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) 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 dd7a042e728..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 @@ -7,14 +7,10 @@ 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.google.common.base.Predicate; import com.sap.sailing.selenium.pages.common.CSSHelper; - import com.sap.sailing.selenium.pages.gwt.CellTablePO; import com.sap.sailing.selenium.pages.gwt.DataEntryPO; - import com.sap.sailing.selenium.pages.leaderboard.LeaderboardTablePO.LeaderboardEntry; public class LeaderboardTablePO extends CellTablePO { @@ -195,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 Predicate() { - @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..bb694c62392 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 @@ -118,7 +118,7 @@ public class TestAutoPlay extends AbstractSeleniumTest { 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(); + leaderBoard.waitForTableToShowData(); List races = leaderBoard.getRaceNames(); Assert.assertTrue(races.contains("R1")); Assert.assertTrue(races.contains("R2")); From 22adfced0ab2dd61f8d3d908969de538a29d18e3 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Fri, 20 Jul 2018 13:10:05 +0200 Subject: [PATCH 2/2] Bug 4675: Ensures that the leaderboard table is visible including data before doing further asserts --- .../sailing/selenium/pages/PageObject.java | 19 +++++++++++ .../autoplay/AutoPlayLeaderboardView.java | 33 +++++++++---------- .../selenium/test/autoplay/TestAutoPlay.java | 3 +- 3 files changed, 36 insertions(+), 19 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 f5b00515f8e..130258175d1 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 @@ -625,4 +625,23 @@ public class PageObject { } throw new NoAlertPresentException(); } + + 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 2dfb1fa7fdd..4b2680b08b4 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 @@ -5,6 +5,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.sap.sailing.selenium.pages.PageArea; import com.sap.sailing.selenium.pages.leaderboard.LeaderboardTablePO; @@ -13,27 +14,15 @@ 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) { - 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 + if (isElementEntirelyVisible(leaderboardCellTable)) { + return leaderboardCellTable; + } else { return null; } } else { @@ -41,7 +30,17 @@ public class AutoPlayLeaderboardView extends PageArea { } } }); - return new LeaderboardTablePO(this.driver, leaderboardCellTable); + 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 Predicate() { + @Override + public boolean apply(WebDriver arg0) { + return isElementEntirelyVisible(leaderboardCellTable); + } + }); + return leaderboardTablePO; } } 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 bb694c62392..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.waitForTableToShowData(); + LeaderboardTablePO leaderBoard = autoplayPage.getLeaderBoardWithData(); List races = leaderBoard.getRaceNames(); Assert.assertTrue(races.contains("R1")); Assert.assertTrue(races.contains("R2"));