8000 Stabilize the test for Chrome (26.8) by mabartos · Pull Request #54960 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
Expand Down Expand Up @@ -57,12 +58,26 @@ public void setDriver(WebDriver driver) {
private void waitForPage(AbstractPage page) {
String expectedPageId = page.getExpectedPageId();
try {
createDefaultWait().ignoring(StaleElementReferenceException.class).until(d -> expectedPageId.equals(getCurrentPageId()));
createDefaultWait().until(d -> isCurrentPageId(expectedPageId));
} catch (TimeoutException e) {
Assertions.fail("Expected page '" + expectedPageId + "' to be loaded, but currently on page '" + getCurrentPageId() + "' after timeout");
}
}

private boolean isCurrentPageId(String expectedPageId) {
try {
return expectedPageId.equals(getCurrentPageId());
} catch (StaleElementReferenceException e) {
return false;
} catch (WebDriverException e) {
// ChromeDriver reports this instead of a stale element when the document is swapped during a navigation
if (e.getMessage() != null && e.getMessage().contains("does not belong to the document")) {
return false;
}
throw e;
}
}

private WebDriverWait createDefaultWait() {
return new WebDriverWait(driver, Duration.ofSeconds(5), Duration.ofMillis(50));
}
Expand Down
Loading
0