From 172ce3554e62f7927eac8fd62756299eb3057967 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Tue, 6 Feb 2024 07:59:58 -0800 Subject: [PATCH] fix: proxy request to the espresso server with nativeWebScreenshot (#978) --- lib/commands/screenshot.js | 18 ++++++++++++++++++ lib/driver.ts | 1 + 2 files changed, 19 insertions(+) diff --git a/lib/commands/screenshot.js b/lib/commands/screenshot.js index c43807eb..93d30ccc 100644 --- a/lib/commands/screenshot.js +++ b/lib/commands/screenshot.js @@ -75,3 +75,21 @@ export async function mobileScreenshots (opts = {}) { } return infos; } + +/** + * Return the base 64 encoded screenshot data. + * This method is called only when `appium:nativeWebScreenshot` is enabled + * to avoid proxying requests to the chromedriver. + * Without `appium:nativeWebScreenshot` or disabled, espresso driver + * proxies screenshot endpoint requests to the espresso server directly. + * + * @this {import('../driver').EspressoDriver} + * @returns {Promise} + */ +export async function getScreenshot() { + return String( + await /** @type {import('../espresso-runner').EspressoRunner} */ ( + this.espresso + ).jwproxy.command('/screenshot', 'GET') + ); +} diff --git a/lib/driver.ts b/lib/driver.ts index 99cbfe1e..55aa9baf 100644 --- a/lib/driver.ts +++ b/lib/driver.ts @@ -735,6 +735,7 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< mobileStartService = servicesCmds.mobileStartService; mobileStopService = servicesCmds.mobileStopService; + getScreenshot = screenshotCmds.getScreenshot; mobileScreenshots = screenshotCmds.mobileScreenshots; mobileRegisterIdlingResources = idlingResourcesCmds.mobileRegisterIdlingResources;