Skip to content

Commit

Permalink
Fix a couple of tests that were failing randomly. (#7739) (#8525)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Carrasco Moñino <[email protected]>
  • Loading branch information
Johannes Eriksson and manolo authored Jun 8, 2020
1 parent bf1a3aa commit de7e21e
Showing 1 changed file with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -36,45 +40,37 @@ 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");
}

@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());
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit de7e21e

Please sign in to comment.