From ba04b288ee688c9755b764193a291f8e5b79d4ad Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Fri, 5 Sep 2025 13:37:57 +0530 Subject: [PATCH] add test for `onHistoryUpdated` event --- .../BrowsingContextInspectorTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java index 93ddcfcb83d10..5b0fad4040d16 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java @@ -21,6 +21,7 @@ import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -29,6 +30,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.module.BrowsingContextInspector; +import org.openqa.selenium.bidi.module.Script; import org.openqa.selenium.testing.JupiterTestBase; import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; @@ -279,4 +281,27 @@ void canListenToNavigationFailedEvent() .isEqualTo("http://invalid-domain-that-does-not-exist.test/"); } } + + @Test + @NeedsFreshDriver + void canListenToHistoryUpdatedEvent() + throws ExecutionException, InterruptedException, TimeoutException { + try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver); + Script script = new Script(driver)) { + CompletableFuture future = new CompletableFuture<>(); + + BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); + context.navigate(appServer.whereIs("/simpleTest.html"), ReadinessState.COMPLETE); + + inspector.onHistoryUpdated(future::complete); + + // Use history.pushState to trigger history updated event + script.evaluateFunctionInBrowsingContext( + context.getId(), "history.pushState({}, '', '/new-path')", false, Optional.empty()); + + HistoryUpdated historyUpdated = future.get(5, TimeUnit.SECONDS); + assertThat(historyUpdated.getBrowsingContextId()).isEqualTo(context.getId()); + assertThat(historyUpdated.getUrl()).contains("/new-path"); + } + } }