|
31 | 31 | import org.openqa.selenium.bidi.module.BrowsingContextInspector; |
32 | 32 | import org.openqa.selenium.testing.JupiterTestBase; |
33 | 33 | import org.openqa.selenium.testing.NeedsFreshDriver; |
| 34 | +import org.openqa.selenium.testing.NotYetImplemented; |
34 | 35 |
|
35 | 36 | class BrowsingContextInspectorTest extends JupiterTestBase { |
36 | 37 |
|
@@ -231,4 +232,50 @@ void canListenToNavigationCommittedEvent() |
231 | 232 | assertThat(navigationInfo.getUrl()).contains("/bidi/logEntryAdded.html"); |
232 | 233 | } |
233 | 234 | } |
| 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 | + } |
234 | 281 | } |
0 commit comments