diff --git a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java index edfb71ef283c7..dd8542e7b6ec1 100644 --- a/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java +++ b/java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java @@ -213,11 +213,10 @@ public void handleUserPrompt(boolean accept, String userText) { ImmutableMap.of(CONTEXT, id, "accept", accept, "userText", userText))); } - // Yet to be implemented by browser vendors - private String captureScreenshot() { + public String captureScreenshot() { return this.bidi.send( new Command<>( - HANDLE_USER_PROMPT, + "browsingContext.captureScreenshot", ImmutableMap.of(CONTEXT, id), jsonInput -> { Map result = jsonInput.read(Map.class); diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java index 33927f4876c44..45cefb6978836 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java @@ -336,6 +336,19 @@ void canDismissUserPromptWithUserText() { assertThat(driver.getPageSource()).doesNotContain(userText); } + @Test + @NotYetImplemented(SAFARI) + @NotYetImplemented(IE) + void canCaptureScreenshot() { + BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); + + driver.get(pages.simpleTestPage); + + String screenshot = browsingContext.captureScreenshot(); + + assertThat(screenshot.length()).isPositive(); + } + private String alertPage() { return appServer.create( new Page()