From f02e917ec618986ffcbf67863acbdc19c8f82036 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Tue, 10 Oct 2023 15:35:51 +0530 Subject: [PATCH] [bidi][java] Add browsing context activate command --- .../bidi/browsingcontext/BrowsingContext.java | 4 ++++ .../browsingcontext/BrowsingContextTest.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java index abc90d5bfc035..d424d678b4530 100644 --- a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java +++ b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java @@ -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. diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java index c065eeb52e4d6..02dbd1e3ed03e 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java @@ -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 @@ -486,6 +502,10 @@ private String promptPage() { "

")); } + private boolean getDocumentFocus() { + return (boolean) ((JavascriptExecutor) driver).executeScript("return document.hasFocus();"); + } + @AfterEach public void quitDriver() { if (driver != null) {