Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,22 @@ public void onBrowsingContextLoaded(Consumer<NavigationInfo> consumer) {
addNavigationEventListener("browsingContext.load", consumer);
}

private void onDownloadWillBegin(Consumer<NavigationInfo> consumer) {
public void onDownloadWillBegin(Consumer<NavigationInfo> consumer) {
addNavigationEventListener("browsingContext.downloadWillBegin", consumer);
}

private void onNavigationAborted(Consumer<NavigationInfo> consumer) {
public void onNavigationAborted(Consumer<NavigationInfo> consumer) {
addNavigationEventListener("browsingContext.navigationAborted", consumer);
}

private void onNavigationFailed(Consumer<NavigationInfo> consumer) {
public void onNavigationFailed(Consumer<NavigationInfo> consumer) {
addNavigationEventListener("browsingContext.navigationFailed", consumer);
}

public void onNavigationCommitted(Consumer<NavigationInfo> consumer) {
addNavigationEventListener("browsingContext.navigationCommitted", consumer);
}

public void onUserPromptClosed(Consumer<UserPromptClosed> consumer) {
if (browsingContextIds.isEmpty()) {
this.bidi.addListener(userPromptClosed, consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.bidi.browsingcontext;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.openqa.selenium.testing.drivers.Browser.*;

import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -30,6 +31,7 @@
import org.openqa.selenium.bidi.module.BrowsingContextInspector;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NeedsFreshDriver;
import org.openqa.selenium.testing.NotYetImplemented;

class BrowsingContextInspectorTest extends JupiterTestBase {

Expand Down Expand Up @@ -213,4 +215,23 @@ void canListenToUserPromptClosedEvent()
assertThat(userPromptClosed.getAccepted()).isTrue();
}
}

@Test
@NeedsFreshDriver
@NotYetImplemented(EDGE)
@NotYetImplemented(FIREFOX)
void canListenToNavigationCommittedEvent()
throws ExecutionException, InterruptedException, TimeoutException {
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();

BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
inspector.onNavigationCommitted(future::complete);
context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);

NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
assertThat(navigationInfo.getUrl()).contains("/bidi/logEntryAdded.html");
}
}
}
Loading