UNPKG

@applitools/driver

Version:

Applitools universal framework wrapper

52 lines (51 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HelperIOS = void 0; class HelperIOS { static async make(options) { const { spec, driver } = options; const element = await driver.element({ type: 'name', selector: 'applitools_grab_scrollable_data_button' }); return element ? new HelperIOS({ driver, element, spec }) : null; } constructor(options) { this._driver = options.driver; this._element = options.element; this._spec = options.spec; this.name = 'ios'; } get logger() { return this._driver.logger; } async getContentRegion(element) { var _a, _b; const { x, y } = await this._spec.getElementRegion(this._driver.target, this._element.target); await this._spec.performAction(this._driver.target, [ { action: 'press', x, y }, { action: 'wait', ms: 300 }, { action: 'release' }, ]); const sizeLabel = await this._driver.element({ type: 'name', selector: 'applitools_content_size_label' }); const sizeString = await (sizeLabel === null || sizeLabel === void 0 ? void 0 : sizeLabel.getText()); if (!sizeString) return null; const [, width, height] = sizeString.match(/\{(-?\d+(?:\.\d+)?),\s?(-?\d+(?:\.\d+)?)\}/); const contentSize = { width: Number(width), height: Number(height) }; if (Number.isNaN(contentSize.width + contentSize.height)) return null; const paddingLabel = await this._driver.element({ type: 'name', selector: 'applitools_content_offset_label' }); const paddingString = await (paddingLabel === null || paddingLabel === void 0 ? void 0 : paddingLabel.getText()); if (paddingString) { const [, x, y] = paddingString.match(/\{(-?\d+(?:\.\d+)?),\s?(-?\d+(?:\.\d+)?)\}/); const contentOffset = { x: Number(x), y: Number(y) }; if (!Number.isNaN(contentOffset.x)) contentSize.width -= contentOffset.x; if (!Number.isNaN(contentOffset.y)) contentSize.height -= contentOffset.y; } const region = await ((_b = (_a = this._spec).getElementRegion) === null || _b === void 0 ? void 0 : _b.call(_a, this._driver.target, element.target)); if (!region || contentSize.height < region.height) return null; return contentSize.height >= region.height ? { x: region.x, y: region.y, ...contentSize } : null; } } exports.HelperIOS = HelperIOS;