Skip to content

Commit 79f73c4

Browse files
committed
[bidi][java] Add browsing context reload methods implemented by the browsers
1 parent 3a126ba commit 79f73c4

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java

+19-12
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,36 @@ public List<BrowsingContextInfo> getTopLevelContexts() {
160160
new Command<>("browsingContext.getTree", new HashMap<>(), browsingContextInfoListMapper));
161161
}
162162

163-
// Yet to be implemented by browser vendors
164-
private void reload() {
165-
this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id)));
163+
public NavigationResult reload() {
164+
return this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id), navigationInfoMapper));
166165
}
167166

168167
// Yet to be implemented by browser vendors
169-
private void reload(boolean ignoreCache) {
170-
this.bidi.send(new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id, "ignoreCache", ignoreCache)));
168+
private NavigationResult reload(boolean ignoreCache) {
169+
return this.bidi.send(new Command<>(
170+
RELOAD,
171+
ImmutableMap.of(CONTEXT, id, "ignoreCache", ignoreCache),
172+
navigationInfoMapper));
171173
}
172174

173-
// Yet to be implemented by browser vendors
174-
private void reload(ReadinessState readinessState) {
175-
this.bidi.send(
176-
new Command<>(RELOAD, ImmutableMap.of(CONTEXT, id, "wait", readinessState.toString())));
175+
// TODO: Handle timeouts in case of Readiness state "interactive" and "complete".
176+
// Refer https://github.com/w3c/webdriver-bidi/issues/188
177+
public NavigationResult reload(ReadinessState readinessState) {
178+
return this.bidi.send(
179+
new Command<>(
180+
RELOAD,
181+
ImmutableMap.of(CONTEXT, id, "wait", readinessState.toString()),
182+
navigationInfoMapper));
177183
}
178184

179185
// Yet to be implemented by browser vendors
180-
private void reload(boolean ignoreCache, ReadinessState readinessState) {
181-
this.bidi.send(
186+
private NavigationResult reload(boolean ignoreCache, ReadinessState readinessState) {
187+
return this.bidi.send(
182188
new Command<>(
183189
RELOAD,
184190
ImmutableMap.of(
185-
CONTEXT, id, "ignoreCache", ignoreCache, "wait", readinessState.toString())));
191+
CONTEXT, id, "ignoreCache", ignoreCache, "wait", readinessState.toString()),
192+
navigationInfoMapper));
186193
}
187194

188195
// Yet to be implemented by browser vendors

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

+30
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,36 @@ void canCloseATab() {
201201
// TODO: Add a test for closing the last tab once the behavior is finalized
202202
// Refer: https://github.com/w3c/webdriver-bidi/issues/187
203203

204+
@Test
205+
@NotYetImplemented(SAFARI)
206+
@NotYetImplemented(IE)
207+
void canReloadABrowsingContext() {
208+
BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB);
209+
210+
String url = server.whereIs("/bidi/logEntryAdded.html");
211+
browsingContext.navigate(url, ReadinessState.COMPLETE);
212+
213+
NavigationResult reloadInfo = browsingContext.reload();
214+
215+
assertThat(reloadInfo.getNavigationId()).isNotNull();
216+
assertThat(reloadInfo.getUrl()).contains("/bidi/logEntryAdded.html");
217+
}
218+
219+
@Test
220+
@NotYetImplemented(SAFARI)
221+
@NotYetImplemented(IE)
222+
void canReloadWithReadinessState() {
223+
BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB);
224+
225+
String url = server.whereIs("/bidi/logEntryAdded.html");
226+
browsingContext.navigate(url, ReadinessState.COMPLETE);
227+
228+
NavigationResult reloadInfo = browsingContext.reload(ReadinessState.COMPLETE);
229+
230+
assertThat(reloadInfo.getNavigationId()).isNotNull();
231+
assertThat(reloadInfo.getUrl()).contains("/bidi/logEntryAdded.html");
232+
}
233+
204234
@AfterEach
205235
public void quitDriver() {
206236
if (driver != null) {

0 commit comments

Comments
 (0)