Skip to content

Commit fa209d1

Browse files
committed
add tests for onDownloadWillBegin and onNavigationFailed
1 parent 12bf38f commit fa209d1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openqa.selenium.bidi.module.BrowsingContextInspector;
3232
import org.openqa.selenium.testing.JupiterTestBase;
3333
import org.openqa.selenium.testing.NeedsFreshDriver;
34+
import org.openqa.selenium.testing.NotYetImplemented;
3435

3536
class BrowsingContextInspectorTest extends JupiterTestBase {
3637

@@ -231,4 +232,50 @@ void canListenToNavigationCommittedEvent()
231232
assertThat(navigationInfo.getUrl()).contains("/bidi/logEntryAdded.html");
232233
}
233234
}
235+
236+
@Test
237+
@NeedsFreshDriver
238+
@NotYetImplemented(FIREFOX)
239+
void canListenToDownloadWillBeginEvent()
240+
throws ExecutionException, InterruptedException, TimeoutException {
241+
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
242+
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
243+
244+
inspector.onDownloadWillBegin(future::complete);
245+
246+
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
247+
context.navigate(appServer.whereIs("/downloads/download.html"), ReadinessState.COMPLETE);
248+
249+
driver.findElement(By.id("file-1")).click();
250+
251+
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
252+
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
253+
assertThat(navigationInfo.getUrl()).contains("/downloads/file_1.txt");
254+
}
255+
}
256+
257+
@Test
258+
@NeedsFreshDriver
259+
@NotYetImplemented(FIREFOX)
260+
void canListenToNavigationFailedEvent()
261+
throws ExecutionException, InterruptedException, TimeoutException {
262+
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
263+
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
264+
265+
inspector.onNavigationFailed(future::complete);
266+
267+
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
268+
try {
269+
context.navigate(
270+
"http://invalid-domain-that-does-not-exist.test/", ReadinessState.COMPLETE);
271+
} catch (Exception e) {
272+
// Expect an exception due to navigation failure
273+
}
274+
275+
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
276+
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
277+
assertThat(navigationInfo.getUrl())
278+
.isEqualTo("http://invalid-domain-that-does-not-exist.test/");
279+
}
280+
}
234281
}

0 commit comments

Comments
 (0)