-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mobile: wrappers for clipboard APIs (#800)
- Loading branch information
1 parent
07fe6bb
commit 7789b1d
Showing
6 changed files
with
106 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @this {AndroidUiautomator2Driver} | ||
* @returns {Promise<string>} Base64-encoded content of the clipboard | ||
* or an empty string if the clipboard is empty. | ||
*/ | ||
export async function getClipboard() { | ||
return String( | ||
(await this.adb.getApiLevel()) < 29 | ||
? await this.uiautomator2.jwproxy.command( | ||
'/appium/device/get_clipboard', | ||
'POST', | ||
{} | ||
) | ||
: await this.settingsApp.getClipboard() | ||
); | ||
} | ||
|
||
/** | ||
* @this {AndroidUiautomator2Driver} | ||
* @returns {Promise<string>} Base64-encoded content of the clipboard | ||
* or an empty string if the clipboard is empty. | ||
*/ | ||
export async function mobileGetClipboard() { | ||
return await this.getClipboard(); | ||
} | ||
|
||
/** | ||
* @this {AndroidUiautomator2Driver} | ||
* @param {string} content Base64-encoded clipboard payload | ||
* @param {'plaintext'} [contentType='plaintext'] Only a single | ||
* content type is supported, which is 'plaintext' | ||
* @param {string} [label] Optinal label to identify the current | ||
* clipboard payload | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function setClipboard(content, contentType, label) { | ||
await this.uiautomator2.jwproxy.command( | ||
'/appium/device/set_clipboard', | ||
'POST', | ||
{content, contentType, label} | ||
); | ||
} | ||
|
||
/** | ||
* @this {AndroidUiautomator2Driver} | ||
* @param {import('./types').SetClipboardOpts} opts | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function mobileSetClipboard(opts) { | ||
await this.setClipboard(opts.content, opts.contentType, opts.label); | ||
} | ||
|
||
/** | ||
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters