Skip to content
Open
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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<HistoryUpdated> 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");
}
}
}
Loading