Skip to content

Commit

Permalink
[bidi][java] Add browsing context activate command
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Oct 10, 2023
1 parent 2ef7031 commit f02e917
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public void setViewport(double width, double height, double devicePixelRatio) {
devicePixelRatio)));
}

public void activate() {
this.bidi.send(new Command<>("browsingContext.activate", Map.of(CONTEXT, id)));
}

public void close() {
// This might need more clean up actions once the behavior is defined.
// Specially when last tab or window is closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ void canCloseATab() {
assertThatExceptionOfType(BiDiException.class).isThrownBy(tab2::getTree);
}

@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(IE)
void canActivateABrowsingContext() {
BrowsingContext window1 = new BrowsingContext(driver, driver.getWindowHandle());
// 2nd window is focused
BrowsingContext window2 = new BrowsingContext(driver, WindowType.WINDOW);

// We did not switch the driver, so we are running the script to check focus on 1st window
assertThat(getDocumentFocus()).isFalse();

window1.activate();

assertThat(getDocumentFocus()).isTrue();
}

// TODO: Add a test for closing the last tab once the behavior is finalized
// Refer: https://github.com/w3c/webdriver-bidi/issues/187

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

private boolean getDocumentFocus() {
return (boolean) ((JavascriptExecutor) driver).executeScript("return document.hasFocus();");
}

@AfterEach
public void quitDriver() {
if (driver != null) {
Expand Down

0 comments on commit f02e917

Please sign in to comment.