From 79f73c469853dad5afffad7f1affbfab70d41830 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Mon, 18 Sep 2023 11:57:25 +0530 Subject: [PATCH] [bidi][java] Add browsing context reload methods implemented by the browsers --- .../bidi/browsingcontext/BrowsingContext.java | 31 ++++++++++++------- .../browsingcontext/BrowsingContextTest.java | 30 ++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java index c3969e2275017..bc8b33a6e068b 100644 --- a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java +++ b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java @@ -160,29 +160,36 @@ public List getTopLevelContexts() { new Command<>("browsingContext.getTree", new HashMap<>(), browsingContextInfoListMapper)); } - // Yet to be implemented by browser vendors - private void reload() { - this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id))); + public NavigationResult reload() { + return this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id), navigationInfoMapper)); } // Yet to be implemented by browser vendors - private void reload(boolean ignoreCache) { - this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id, "ignoreCache", ignoreCache))); + private NavigationResult reload(boolean ignoreCache) { + return this.bidi.send(new Command<>( + RELOAD, + ImmutableMap.of(CONTEXT, id, "ignoreCache", ignoreCache), + navigationInfoMapper)); } - // Yet to be implemented by browser vendors - private void reload(ReadinessState readinessState) { - this.bidi.send( - new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id, "wait", readinessState.toString()))); + // TODO: Handle timeouts in case of Readiness state "interactive" and "complete". + // Refer https://github.com/w3c/webdriver-bidi/issues/188 + public NavigationResult reload(ReadinessState readinessState) { + return this.bidi.send( + new Command<>( + RELOAD, + ImmutableMap.of(CONTEXT, id, "wait", readinessState.toString()), + navigationInfoMapper)); } // Yet to be implemented by browser vendors - private void reload(boolean ignoreCache, ReadinessState readinessState) { - this.bidi.send( + private NavigationResult reload(boolean ignoreCache, ReadinessState readinessState) { + return this.bidi.send( new Command<>( RELOAD, ImmutableMap.of( - CONTEXT, id, "ignoreCache", ignoreCache, "wait", readinessState.toString()))); + CONTEXT, id, "ignoreCache", ignoreCache, "wait", readinessState.toString()), + navigationInfoMapper)); } // Yet to be implemented by browser vendors diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java index 4ccfe4c8ca88f..ba50fa9c4854f 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java @@ -201,6 +201,36 @@ void canCloseATab() { // TODO: Add a test for closing the last tab once the behavior is finalized // Refer: https://github.com/w3c/webdriver-bidi/issues/187 + @Test + @NotYetImplemented(SAFARI) + @NotYetImplemented(IE) + void canReloadABrowsingContext() { + BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); + + String url = server.whereIs("/bidi/logEntryAdded.html"); + browsingContext.navigate(url, ReadinessState.COMPLETE); + + NavigationResult reloadInfo = browsingContext.reload(); + + assertThat(reloadInfo.getNavigationId()).isNotNull(); + assertThat(reloadInfo.getUrl()).contains("/bidi/logEntryAdded.html"); + } + + @Test + @NotYetImplemented(SAFARI) + @NotYetImplemented(IE) + void canReloadWithReadinessState() { + BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); + + String url = server.whereIs("/bidi/logEntryAdded.html"); + browsingContext.navigate(url, ReadinessState.COMPLETE); + + NavigationResult reloadInfo = browsingContext.reload(ReadinessState.COMPLETE); + + assertThat(reloadInfo.getNavigationId()).isNotNull(); + assertThat(reloadInfo.getUrl()).contains("/bidi/logEntryAdded.html"); + } + @AfterEach public void quitDriver() { if (driver != null) {