From ea453abd42469878c1579a712af60b28b4c180d9 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Fri, 20 Jul 2018 16:27:53 +0200 Subject: [PATCH 1/2] Bug 4675: Waiting for the leaderboard in AutoPlay does not work in all cases because the auto-zoom can break this too. With this change we do not wait for the leaderboard table anymore but the LeaderboardView to get visible. With this change we can be sure that the leaderboard is visible even if the auto zoom changes the size of the leaderboard table while reading the view contents. --- .../autoplay/AutoPlayLeaderboardView.java | 29 +------------------ .../selenium/pages/autoplay/AutoPlayPage.java | 22 +++++++++++--- 2 files changed, 19 insertions(+), 32 deletions(-) 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 4b2680b08b4..6eb5e109618 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,10 +2,7 @@ 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.google.common.base.Predicate; import com.sap.sailing.selenium.pages.PageArea; import com.sap.sailing.selenium.pages.leaderboard.LeaderboardTablePO; @@ -15,32 +12,8 @@ public class AutoPlayLeaderboardView extends PageArea { } 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) { - if (isElementEntirelyVisible(leaderboardCellTable)) { - return leaderboardCellTable; - } else { - return null; - } - } else { - return null; - } - } - }); - LeaderboardTablePO leaderboardTablePO = new LeaderboardTablePO(this.driver, leaderboardCellTable); + LeaderboardTablePO leaderboardTablePO = new LeaderboardTablePO(this.driver, findElementBySeleniumId("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/pages/autoplay/AutoPlayPage.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayPage.java index c37d75e80f6..d06aa9931e9 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayPage.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/autoplay/AutoPlayPage.java @@ -4,7 +4,9 @@ import java.io.UnsupportedEncodingException; 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.core.BySeleniumId; import com.sap.sailing.selenium.core.FindBy; import com.sap.sailing.selenium.pages.HostPage; @@ -21,9 +23,6 @@ public class AutoPlayPage extends HostPage { @FindBy(how = BySeleniumId.class, using = "AutoPlayStartView") private WebElement autoPlayStartView; - @FindBy(how = BySeleniumId.class, using = "LeaderboardView") - private WebElement autoPlayLeaderboardView; - @FindBy(how = BySeleniumId.class, using = "IdleNextUpView") private WebElement idleNextUpView; @@ -76,7 +75,22 @@ public class AutoPlayPage extends HostPage { public AutoPlayLeaderboardView goToAutoPlayClassicUrl(WebDriver driver, String url) { driver.get(url); //$NON-NLS-1$ - return new AutoPlayLeaderboardView(driver, autoPlayLeaderboardView); + final WebElement leaderboardViewElement = new WebDriverWait(driver, 30).until(new Function() { + @Override + public WebElement apply(WebDriver driver) { + final WebElement leaderboardViewElement = findElementOrNullBySeleniumId("LeaderboardView"); + if (leaderboardViewElement != null) { + if (isElementEntirelyVisible(leaderboardViewElement)) { + return leaderboardViewElement; + } else { + return null; + } + } else { + return null; + } + } + }); + return new AutoPlayLeaderboardView(driver, leaderboardViewElement); } public AutoPlayUpcomingView goToAutoPlaySixtyInchUrl(WebDriver webDriver, String url) { From 4cf7d27c8447dda08d62f4cdad82310aa27e46d1 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Fri, 20 Jul 2018 16:35:03 +0200 Subject: [PATCH 2/2] Bug 4675: Changes to make the AutoPlay test robust regarding auto update of the leaderboard table --- .../selenium/test/autoplay/TestAutoPlay.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 f79a99f3baf..7ed39aa5877 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 @@ -12,7 +12,10 @@ import javax.xml.bind.DatatypeConverter; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import com.google.common.base.Function; import com.sap.sailing.selenium.pages.adminconsole.AdminConsolePage; import com.sap.sailing.selenium.pages.adminconsole.event.EventConfigurationPanelPO; import com.sap.sailing.selenium.pages.adminconsole.leaderboard.LeaderboardConfigurationPanelPO; @@ -118,7 +121,26 @@ 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.getLeaderBoardWithData(); - List races = leaderBoard.getRaceNames(); + final List races = new WebDriverWait(getWebDriver(), 20).until(new Function>() { + @Override + public List apply(WebDriver arg0) { + try { + final List races = leaderBoard.getRaceNames(); + final List result; + if (races != null && !races.isEmpty()) { + result = races; + } else { + // The table may seem to be empty while the leaderboard updates itself + result = null; + } + return result; + } catch (Exception e) { + // While the leaderboard updates its contents, errors may occur while reading data via selenium + // In this case we need to try this in the next loop again + return null; + } + } + }); Assert.assertTrue(races.contains("R1")); Assert.assertTrue(races.contains("R2")); Assert.assertTrue(races.contains("R3"));