Skip to content

Commit

Permalink
feat: Add support of executeMethodMap (#1042)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The following methods and properties were **removed**:
- mobileCommandsMapping
- mobileBackgroundApp

BREAKING CHANGE: The following methods signatures were **changed**:
- mobileSwipe
- mobileScrollToPage
- mobileClickAction
- mobileNavigateTo
- mobileIsToastVisible
- mobileOpenDrawer
- mobileCloseDrawer
- mobileSetDate
- mobileSetTime
- mobileBackdoor
- mobileFlashElement
- mobileUiautomator
- mobileWebAtoms
- mobileDismissAutofill
- mobileRegisterIdlingResources
- mobileUnregisterIdlingResources
- mobilePressKey
- mobileSetClipboard
- mobileStartService
- mobileStopService
- mobileStartActivity
- mobileScreenshots

Based on appium/appium-android-driver#982
  • Loading branch information
mykola-mokhnach authored Feb 1, 2025
1 parent 9dfbbe7 commit 00a38a2
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 294 deletions.
49 changes: 11 additions & 38 deletions lib/commands/app-management.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
import { qualifyActivityName, requireOptions } from '../utils';

/**
* @typedef {Object} BackgroundAppOptions
* @property {number} [seconds] The amount of seconds to wait between putting the app to background and restoring it.
* Any negative value means to not restore the app after putting it to the background (the default behavior).
*/

/**
* Puts the app under test to the background
* and then restores it (if needed). The call is blocking is the
* app needs to be restored afterwards.
*
* @this {import('../driver').EspressoDriver}
* @param {BackgroundAppOptions} [opts={}]
*/
export async function mobileBackgroundApp (opts = {}) {
const {seconds = -1} = opts;
return await this.background(seconds);
}

/**
* @overload
* @typedef {Object} StartActivityOptions
* @property {string} appActivity
* @property {string} [locale]
* @property {string} [optionalIntentArguments]
* @property {string} [optionalActivityArguments]
*/
import { qualifyActivityName } from '../utils';

/**
* Starts the given activity with intent options, activity options and locale.
* Activity could only be executed in scope of the current app package.
*
* @this {import('../driver').EspressoDriver}
* @overload
* @param {StartActivityOptions} opts
* @param {string} appActivity
* @param {string} [locale]
* @param {string} [optionalIntentArguments]
* @param {string} [optionalActivityArguments]
* @returns {Promise<string>}
*/
export async function mobileStartActivity (opts) {
export async function mobileStartActivity (
appActivity,
locale,
optionalIntentArguments,
optionalActivityArguments
) {
const appPackage = this.caps.appPackage;
const {
appActivity,
locale,
optionalIntentArguments,
optionalActivityArguments
} = requireOptions(opts, ['appActivity']);
return /** @type {string} */ (await this.espresso.jwproxy.command(`/appium/device/start_activity`, 'POST', {
appPackage,
appActivity,
Expand Down
22 changes: 6 additions & 16 deletions lib/commands/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @this {import('../driver').EspressoDriver}
* @this {EspressoDriver}
* @returns {Promise<string>} Base64-encoded content of the clipboard
* or an empty string if the clipboard is empty.
*/
Expand All @@ -10,25 +10,15 @@ export async function getClipboard () {
}

/**
* @typedef {Object} SetClipboardOptions
* @property {string} content Base64-encoded clipboard payload
* @property {'plaintext'} [contentType] Only a single
* @this {EspressoDriver}
* @param {string} content Base64-encoded clipboard payload
* @param {'plaintext'} [contentType] Only a single
* content type is supported, which is 'plaintext'
* @property {string} [label] Optinal label to identify the current
* @param {string} [label] Optinal label to identify the current
* clipboard payload
*/

/**
* @this {EspressoDriver}
* @param {SetClipboardOptions} opts
* @returns {Promise<void>}
*/
export async function mobileSetClipboard(opts) {
const {
content,
contentType,
label,
} = opts;
export async function mobileSetClipboard(content, contentType, label) {
await this.espresso.jwproxy.command(
'/appium/device/set_clipboard',
'POST',
Expand Down
19 changes: 14 additions & 5 deletions lib/commands/context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { requireOptions } from '../utils';

/**
* Stop proxying to any Chromedriver and redirect to Espresso
*
Expand Down Expand Up @@ -27,8 +25,19 @@ export function suspendChromedriverProxy () {
* ]
* }
* @this {import('../driver').EspressoDriver}
* @see https://github.com/appium/appium-espresso-driver?tab=readme-ov-file#mobile-webatoms
* @param {string} webviewEl
* @param {boolean} forceJavascriptEnabled
* @param {import('@appium/types').StringRecord[]} methodChain
*/
export async function mobileWebAtoms (opts = {}) {
opts = requireOptions(opts, ['methodChain']);
return await this.espresso.jwproxy.command(`/appium/execute_mobile/web_atoms`, 'POST', opts);
export async function mobileWebAtoms (
webviewEl,
forceJavascriptEnabled,
methodChain
) {
return await this.espresso.jwproxy.command(`/appium/execute_mobile/web_atoms`, 'POST', {
webviewEl,
forceJavascriptEnabled,
methodChain,
});
}
Loading

0 comments on commit 00a38a2

Please sign in to comment.