| 
21 | 21 | import static org.openqa.selenium.testing.drivers.Browser.*;  | 
22 | 22 | 
 
  | 
23 | 23 | import java.util.List;  | 
 | 24 | +import java.util.Optional;  | 
24 | 25 | import java.util.concurrent.CompletableFuture;  | 
25 | 26 | import java.util.concurrent.ExecutionException;  | 
26 | 27 | import java.util.concurrent.TimeUnit;  | 
 | 
29 | 30 | import org.openqa.selenium.By;  | 
30 | 31 | import org.openqa.selenium.WindowType;  | 
31 | 32 | import org.openqa.selenium.bidi.module.BrowsingContextInspector;  | 
 | 33 | +import org.openqa.selenium.bidi.module.Script;  | 
32 | 34 | import org.openqa.selenium.testing.JupiterTestBase;  | 
33 | 35 | import org.openqa.selenium.testing.NeedsFreshDriver;  | 
34 | 36 | import org.openqa.selenium.testing.NotYetImplemented;  | 
@@ -279,4 +281,27 @@ void canListenToNavigationFailedEvent()  | 
279 | 281 |           .isEqualTo("http://invalid-domain-that-does-not-exist.test/");  | 
280 | 282 |     }  | 
281 | 283 |   }  | 
 | 284 | + | 
 | 285 | +  @Test  | 
 | 286 | +  @NeedsFreshDriver  | 
 | 287 | +  void canListenToHistoryUpdatedEvent()  | 
 | 288 | +      throws ExecutionException, InterruptedException, TimeoutException {  | 
 | 289 | +    try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver);  | 
 | 290 | +        Script script = new Script(driver)) {  | 
 | 291 | +      CompletableFuture<HistoryUpdated> future = new CompletableFuture<>();  | 
 | 292 | + | 
 | 293 | +      BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());  | 
 | 294 | +      context.navigate(appServer.whereIs("/simpleTest.html"), ReadinessState.COMPLETE);  | 
 | 295 | + | 
 | 296 | +      inspector.onHistoryUpdated(future::complete);  | 
 | 297 | + | 
 | 298 | +      // Use history.pushState to trigger history updated event  | 
 | 299 | +      script.evaluateFunctionInBrowsingContext(  | 
 | 300 | +          context.getId(), "history.pushState({}, '', '/new-path')", false, Optional.empty());  | 
 | 301 | + | 
 | 302 | +      HistoryUpdated historyUpdated = future.get(5, TimeUnit.SECONDS);  | 
 | 303 | +      assertThat(historyUpdated.getBrowsingContextId()).isEqualTo(context.getId());  | 
 | 304 | +      assertThat(historyUpdated.getUrl()).contains("/new-path");  | 
 | 305 | +    }  | 
 | 306 | +  }  | 
282 | 307 | }  | 
0 commit comments