Skip to content

Commit ba04b28

Browse files
committed
add test for onHistoryUpdated event
1 parent 01548e0 commit ba04b28

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.openqa.selenium.testing.drivers.Browser.*;
2222

2323
import java.util.List;
24+
import java.util.Optional;
2425
import java.util.concurrent.CompletableFuture;
2526
import java.util.concurrent.ExecutionException;
2627
import java.util.concurrent.TimeUnit;
@@ -29,6 +30,7 @@
2930
import org.openqa.selenium.By;
3031
import org.openqa.selenium.WindowType;
3132
import org.openqa.selenium.bidi.module.BrowsingContextInspector;
33+
import org.openqa.selenium.bidi.module.Script;
3234
import org.openqa.selenium.testing.JupiterTestBase;
3335
import org.openqa.selenium.testing.NeedsFreshDriver;
3436
import org.openqa.selenium.testing.NotYetImplemented;
@@ -279,4 +281,27 @@ void canListenToNavigationFailedEvent()
279281
.isEqualTo("http://invalid-domain-that-does-not-exist.test/");
280282
}
281283
}
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+
}
282307
}

0 commit comments

Comments
 (0)