From de7e21e61f1539a5cd88ada64d1bdbb1ca5d6b42 Mon Sep 17 00:00:00 2001 From: Johannes Eriksson Date: Mon, 8 Jun 2020 19:10:24 +0300 Subject: [PATCH] Fix a couple of tests that were failing randomly. (#7739) (#8525) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Carrasco MoƱino --- .../flow/uitest/ui/InternalErrorIT.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/InternalErrorIT.java b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/InternalErrorIT.java index 7be76922609..191cbd13f0b 100644 --- a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/InternalErrorIT.java +++ b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/InternalErrorIT.java @@ -23,9 +23,13 @@ import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; import com.vaadin.flow.testutil.ChromeBrowserTest; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Tests for handling internal errors and session expiration * @@ -36,12 +40,10 @@ public class InternalErrorIT extends ChromeBrowserTest { private static final String UPDATE = "update"; private static final String CLOSE_SESSION = "close-session"; - private int count; @Override public void setup() throws Exception { super.setup(); - open(); // make sure system message provider is resets clickButton("reset-system-messages"); @@ -49,32 +51,26 @@ public void setup() throws Exception { @Test public void sessionExpired_refreshByDefault() { + // Put a flag in the current window + executeScript("window.foo = true"); + assertTrue((boolean)executeScript("return !!window.foo;")); + + // Click on a button that should update the UI clickButton(UPDATE); - clickButton(CLOSE_SESSION); + waitUntil(driver -> isMessageUpdated()); - // Just click on any button to make a request after killing the session + // Expire the session clickButton(CLOSE_SESSION); - try { - waitUntil(driver -> { - if (!isMessageUpdated()) { - return true; - } - if (count % 2 == 0) { - clickButton(UPDATE); - } else { - clickButton(CLOSE_SESSION); - } - count++; - return false; - }); - } catch (TimeoutException e) { - Assert.fail( - "After killing the session, the page should be refreshed, " - + "resetting the state of the UI."); - } + // Wait until the UI does not have the updated message + waitUntil(driver -> !isMessageUpdated()); - Assert.assertFalse( + // window has been reloaded, thus, the flag must not be + // in the new window + assertFalse((boolean)executeScript("return !!window.foo;")); + + // Check that there is no notification about session expired + assertFalse( "By default, the 'Session Expired' notification " + "should not be used", isSessionExpiredNotificationPresent()); @@ -154,6 +150,8 @@ public void internalError_showNotification_clickEsc_refresh() { @After public void resetSystemMessages() { + waitUntil(ExpectedConditions + .presenceOfElementLocated(By.id("reset-system-messages"))); clickButton("reset-system-messages"); }