From 005acbdd05ac2aefe954eb66078f94c4f2c33f02 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Thu, 26 Jul 2018 09:41:36 +0200 Subject: [PATCH] Bug 4339: Fix for non deterministic test failure due to waitForAjaxRequests not being successful because of many parallel remote calls --- .../selenium/pages/common/DataEntryDialogPO.java | 16 +++++++--------- .../TestLeaderboardConfiguration.java | 4 ++-- .../selenium/test/raceboard/SettingsTest.java | 8 +++++++- 3 files changed, 16 insertions(+), 12 deletions(-) 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 9af52e4a4f1..bca0bfc7a61 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 @@ -7,8 +7,8 @@ import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import com.sap.sailing.selenium.core.BySeleniumId; import com.sap.sailing.selenium.core.FindBy; @@ -59,10 +59,10 @@ public abstract class DataEntryDialogPO extends PageArea { } public void pressOk() { - pressOk(false); + pressOk(false, true); } - public void pressOk(boolean accept) { + public void pressOk(boolean acceptAlert, boolean waitForAjaxRequests) { // This generically triggers revalidation in dialogs to ensure that the ok button gets enabled ((JavascriptExecutor) driver).executeScript("!!document.activeElement ? document.activeElement.blur() : 0"); @@ -71,15 +71,13 @@ public abstract class DataEntryDialogPO extends PageArea { waitUntil(() -> isElementEntirelyVisible(this.okButton) && this.okButton.isEnabled()); this.okButton.click(); - - ExpectedCondition condition = ExpectedConditions.alertIsPresent(); - Alert alert = condition.apply(this.driver); - - if(alert != null && accept) { + if (acceptAlert) { + final Alert alert = new WebDriverWait(driver, DEFAULT_WAIT_TIMEOUT_SECONDS) + .until(ExpectedConditions.alertIsPresent()); alert.accept(); } - if(alert == null || accept) { + if (waitForAjaxRequests) { // Wait, since we do a callback usually waitForAjaxRequests(); } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestLeaderboardConfiguration.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestLeaderboardConfiguration.java index cc2e1ea22b5..6699a1c14c6 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestLeaderboardConfiguration.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestLeaderboardConfiguration.java @@ -130,7 +130,7 @@ public class TestLeaderboardConfiguration extends AbstractSeleniumTest { RegattaDetailsCompositePO regattaDetails = regattaStructure.getRegattaDetails(this.regatta); SeriesEditDialogPO seriesDialog = regattaDetails.editSeries(RegattaStructureManagementPanelPO.DEFAULT_SERIES_NAME); seriesDialog.deleteRace("D3"); - seriesDialog.pressOk(true); + seriesDialog.pressOk(true, false); final List expectedRaces = Arrays.asList("D1", "D2", "D4", "D5"); regattaDetails.waitForRacesOfSeries(RegattaStructureManagementPanelPO.DEFAULT_SERIES_NAME, expectedRaces); // Now we can check the result with our expectation @@ -169,7 +169,7 @@ public class TestLeaderboardConfiguration extends AbstractSeleniumTest { RegattaDetailsCompositePO regattaDetails = regattaStructure.getRegattaDetails(this.regatta); SeriesEditDialogPO seriesDialog = regattaDetails.editSeries(RegattaStructureManagementPanelPO.DEFAULT_SERIES_NAME); seriesDialog.renameRace("D1", "Q"); - seriesDialog.pressOk(true); + seriesDialog.pressOk(true, false); // Now we can check the result with our expectation leaderboardWindow.switchToWindow(); diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/raceboard/SettingsTest.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/raceboard/SettingsTest.java index 4d4d9ff3822..130db322224 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/raceboard/SettingsTest.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/raceboard/SettingsTest.java @@ -198,7 +198,13 @@ public class SettingsTest extends AbstractSeleniumTest { Assert.assertFalse(mapSettings.isTransparentHoverlines()); mapSettings.setWindUp(false); mapSettings.setTransparentHoverlines(false); - mapSettings.pressOk(); + + // When just doing mapSettings.pressOk() this test often fails because the internally called waitForAjaxRequests + // often never terminates because many components do parallel calls in short cycles + // That's why we do not want to use waitForAjaxRequests here but instead wait a fix amount of time as workaround + // TODO this could be improved by using a specific category for saving settings so that we could explicitly wait for this + mapSettings.pressOk(false, false); + Thread.sleep(5000); raceboard = RaceBoardPage.goToRaceboardUrl(getWebDriver(), getContextRoot(), BMW_CUP_REGATTA, BMW_CUP_REGATTA, String.format(BMW_RACE, 1), "WINNING_LANES");