From 83a27e797cb1876d89fa3a0578cbc11666d1fd26 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 20 Sep 2023 11:49:07 +0530 Subject: [PATCH] [bidi][java] Add browsing context capture screenshot method --- .../bidi/browsingcontext/BrowsingContext.java | 5 ++--- .../bidi/browsingcontext/BrowsingContextTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) 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()