Skip to content

Commit

Permalink
test: fix redirect after logout test (#20904)
Browse files Browse the repository at this point in the history
Retries JS execution several times to prevent test failures cause
by aborted navigation on the browser.
  • Loading branch information
mcollovati authored Jan 24, 2025
1 parent f344141 commit 50947e8
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;

import com.vaadin.flow.component.button.testbench.ButtonElement;
import com.vaadin.flow.component.upload.testbench.UploadElement;
Expand Down Expand Up @@ -423,9 +425,21 @@ private void waitForUploads(UploadElement element, int maxSeconds) {
* Static caching done by #isClientRouter can cause some tests to be flaky.
*/
protected void waitForClientRouter() {
boolean hasClientRouter = (boolean) executeScript(
"return !!window.Vaadin.Flow.clients.TypeScript");
if (hasClientRouter) {
AtomicBoolean hasClientRouter = new AtomicBoolean(false);
// Tries the JS execution several times, to prevent failures caused
// by redirects and page reloads, such as the following error seen
// more frequently with Chrome 132
// aborted by navigation: loader has changed while resolving nodes
waitUntil(d -> {
try {
hasClientRouter.set((boolean) executeScript(
"return !!window.Vaadin.Flow.clients.TypeScript"));
return true;
} catch (WebDriverException expected) {
return false;
}
});
if (hasClientRouter.get()) {
waitForElementPresent(By.cssSelector("#outlet > *"));
}
}
Expand Down

0 comments on commit 50947e8

Please sign in to comment.