appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
60 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PasteboardClient = void 0;
/**
* Pasteboard service on real hardware.
*
* Requires **iOS/tvOS 17+** and the optional **`appium-ios-remotexpc`** package.
*/
class PasteboardClient {
udid;
remoteXPCFacade;
constructor(udid, remoteXPCFacade) {
this.udid = udid;
this.remoteXPCFacade = remoteXPCFacade;
}
async setPasteboard(content, contentType) {
await this.withPasteboardService(async (pasteboardService) => {
switch (contentType) {
case 'image':
await pasteboardService.setImage(Buffer.from(content, 'base64'));
break;
case 'url':
await pasteboardService.setUrl(content);
break;
default:
await pasteboardService.setText(content);
break;
}
});
}
async getPasteboard(contentType) {
return await this.withPasteboardService(async (pasteboardService) => {
switch (contentType) {
case 'url': {
const url = await pasteboardService.getUrl();
return url === undefined ? undefined : url.toString();
}
case 'image': {
const image = await pasteboardService.getImage();
return image === undefined ? undefined : image.toString('base64');
}
default: {
const text = await pasteboardService.getText();
return text === undefined ? undefined : text;
}
}
});
}
async withPasteboardService(operation) {
const pasteboardService = await this.remoteXPCFacade.requireService('Pasteboard', (Services) => Services.startPasteboardService(this.udid));
try {
return await operation(pasteboardService);
}
finally {
await pasteboardService.close();
}
}
}
exports.PasteboardClient = PasteboardClient;
//# sourceMappingURL=pasteboard-client.js.map