UNPKG

multi-automator

Version:
70 lines (69 loc) 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @desc: iOS Element * @author: john_chen * @date: 2025.02.15 */ const fs_1 = require("fs"); const config_1 = require("../config"); class Element { constructor(options) { this.device = options.device; this.element = options.element; } async tap() { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.tap] ${this.element.ELEMENT}`); return await this.device.wda.post(`/element/${this.element.ELEMENT}/click`, {}, { withSession: true }); } async clear() { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.clear] ${this.element.ELEMENT}`); return await this.device.wda.post(`/element/${this.element.ELEMENT}/clear`, {}, { withSession: true }); } async input(text) { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.input] ${this.element.ELEMENT} ${text}`); return await this.device.wda.post(`/element/${this.element.ELEMENT}/value`, { value: [text] }, { withSession: true }); } async screenshot(path) { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.screenshot] ${this.element.ELEMENT} ${path}`); const base64Data = await this.device.wda.get(`/element/${this.element.ELEMENT}/screenshot`, { withSession: true }); const buffer = Buffer.from(base64Data, 'base64'); if (path) { (0, fs_1.writeFileSync)(path, buffer); } return buffer; } async attribute(name) { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.attribute] ${this.element.ELEMENT} ${name}`); return await this.device.wda.get(`/element/${this.element.ELEMENT}/attribute/${name}`, { withSession: true }); } async boundingBox() { var _a; if (!((_a = this.device) === null || _a === void 0 ? void 0 : _a.wda)) { throw new Error('WDA client is not initialized'); } config_1.logger.info(`[Element.boundingBox] ${this.element.ELEMENT}`); return await this.device.wda.get(`/element/${this.element.ELEMENT}/rect`, { withSession: true }); } } exports.default = Element;