Skip to content

Commit f02e917

Browse files
committed
[bidi][java] Add browsing context activate command
1 parent 2ef7031 commit f02e917

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ public void setViewport(double width, double height, double devicePixelRatio) {
315315
devicePixelRatio)));
316316
}
317317

318+
public void activate() {
319+
this.bidi.send(new Command<>("browsingContext.activate", Map.of(CONTEXT, id)));
320+
}
321+
318322
public void close() {
319323
// This might need more clean up actions once the behavior is defined.
320324
// Specially when last tab or window is closed.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ void canCloseATab() {
207207
assertThatExceptionOfType(BiDiException.class).isThrownBy(tab2::getTree);
208208
}
209209

210+
@Test
211+
@NotYetImplemented(SAFARI)
212+
@NotYetImplemented(IE)
213+
void canActivateABrowsingContext() {
214+
BrowsingContext window1 = new BrowsingContext(driver, driver.getWindowHandle());
215+
// 2nd window is focused
216+
BrowsingContext window2 = new BrowsingContext(driver, WindowType.WINDOW);
217+
218+
// We did not switch the driver, so we are running the script to check focus on 1st window
219+
assertThat(getDocumentFocus()).isFalse();
220+
221+
window1.activate();
222+
223+
assertThat(getDocumentFocus()).isTrue();
224+
}
225+
210226
// TODO: Add a test for closing the last tab once the behavior is finalized
211227
// Refer: https://github.com/w3c/webdriver-bidi/issues/187
212228

@@ -486,6 +502,10 @@ private String promptPage() {
486502
"<p id=\"result\"></p>"));
487503
}
488504

505+
private boolean getDocumentFocus() {
506+
return (boolean) ((JavascriptExecutor) driver).executeScript("return document.hasFocus();");
507+
}
508+
489509
@AfterEach
490510
public void quitDriver() {
491511
if (driver != null) {

0 commit comments

Comments
 (0)