io.appium.settings
Version:
App for dealing with Android settings
41 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getClipboard = getClipboard;
const logger_1 = require("../logger");
const constants_1 = require("../constants");
/**
* Retrieves the text content of the device's clipboard.
* The method works for Android below and above 29.
* It temporarily enforces the IME setting in order to workaround
* security limitations if needed.
* This method only works if Appium Settings v. 2.15+ is installed
* on the device under test
*
* @returns The actual content of the main clipboard as base64-encoded string or an empty string if the clipboard is empty
* @throws {Error} If there was a problem while getting the clipboard content
*/
async function getClipboard() {
this.log.debug(logger_1.LOG_PREFIX, 'Getting the clipboard content');
await this.requireRunning({ shouldRestoreCurrentApp: true });
const retrieveClipboard = async () => await this.checkBroadcast([
'-n', constants_1.CLIPBOARD_RECEIVER,
'-a', constants_1.CLIPBOARD_RETRIEVAL_ACTION,
], 'retrieve clipboard', false);
let output;
try {
output = (await this.adb.getApiLevel() >= 29)
? (await this.adb.runInImeContext(constants_1.APPIUM_IME, retrieveClipboard))
: (await retrieveClipboard());
}
catch (err) {
throw new Error(`Cannot retrieve the current clipboard content from the device. ` +
`Make sure the Appium Settings application is up to date. ` +
`Original error: ${err.message}`);
}
const match = /data="([^"]*)"/.exec(output);
if (!match) {
throw new Error(`Cannot parse the actual clipboard content from the command output: ${output}`);
}
return match[1].trim();
}
//# sourceMappingURL=clipboard.js.map