UNPKG

appium-android-driver

Version:

Android UiAutomator and Chrome support for Appium

181 lines 6.56 kB
"use strict"; /* eslint-disable @typescript-eslint/no-unused-vars */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getAttribute = getAttribute; exports.click = click; exports.getText = getText; exports.getLocation = getLocation; exports.getSize = getSize; exports.getName = getName; exports.elementDisplayed = elementDisplayed; exports.elementEnabled = elementEnabled; exports.elementSelected = elementSelected; exports.setElementValue = setElementValue; exports.doSetElementValue = doSetElementValue; exports.setValue = setValue; exports.replaceValue = replaceValue; exports.setValueImmediate = setValueImmediate; exports.getLocationInView = getLocationInView; const driver_1 = require("appium/driver"); /** * Gets an attribute value from an element. * * @param attribute The name of the attribute to retrieve. * @param elementId The element identifier. * @returns Promise that resolves to the attribute value, or `null` if not found. * @throws {errors.NotImplementedError} This method is not implemented. */ async function getAttribute(attribute, elementId) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Clicks on an element. * * @param elementId The element identifier. * @returns Promise that resolves when the click is performed. * @throws {errors.NotImplementedError} This method is not implemented. */ async function click(elementId) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Gets the text content of an element. * * @param elementId The element identifier. * @returns Promise that resolves to the element's text content. * @throws {errors.NotImplementedError} This method is not implemented. */ async function getText(elementId) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Gets the location of an element on the screen. * * @param elementId The element identifier. * @returns Promise that resolves to the element's position (x, y coordinates). * @throws {errors.NotImplementedError} This method is not implemented. */ async function getLocation(elementId) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Gets the size of an element. * * @param elementId The element identifier. * @returns Promise that resolves to the element's size (width, height). * @throws {errors.NotImplementedError} This method is not implemented. */ async function getSize(elementId) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Gets the class name of an element. * * @param elementId The element identifier. * @returns Promise that resolves to the element's class name. */ async function getName(elementId) { return await this.getAttribute('className', elementId); } /** * Checks if an element is displayed. * * @param elementId The element identifier. * @returns Promise that resolves to `true` if the element is displayed, `false` otherwise. */ async function elementDisplayed(elementId) { return (await this.getAttribute('displayed', elementId)) === 'true'; } /** * Checks if an element is enabled. * * @param elementId The element identifier. * @returns Promise that resolves to `true` if the element is enabled, `false` otherwise. */ async function elementEnabled(elementId) { return (await this.getAttribute('enabled', elementId)) === 'true'; } /** * Checks if an element is selected. * * @param elementId The element identifier. * @returns Promise that resolves to `true` if the element is selected, `false` otherwise. */ async function elementSelected(elementId) { return (await this.getAttribute('selected', elementId)) === 'true'; } /** * Sets the value of an element. * * @param keys The text to set, either as a string or an array of strings (which will be joined). * @param elementId The element identifier. * @param replace If `true`, replaces the existing value. If `false`, appends to it. Defaults to `false`. * @returns Promise that resolves when the value is set. */ async function setElementValue(keys, elementId, replace = false) { const text = keys instanceof Array ? keys.join('') : keys; return await this.doSetElementValue({ elementId, text: String(text), replace, }); } /** * Sets the value of an element. * * Reason for isolating doSetElementValue from setElementValue is for reusing setElementValue * across android-drivers (like appium-uiautomator2-driver) and to avoid code duplication. * Other android-drivers (like appium-uiautomator2-driver) need to override doSetElementValue * to facilitate setElementValue. * * @param params The parameters for setting the element value. * @returns Promise that resolves when the value is set. * @throws {errors.NotImplementedError} This method is not implemented. */ async function doSetElementValue(params) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Sets the value of an element (appends to existing value). * * @param keys The text to set, either as a string or an array of strings (which will be joined). * @param elementId The element identifier. * @returns Promise that resolves when the value is set. */ async function setValue(keys, elementId) { return await this.setElementValue(keys, elementId, false); } /** * Replaces the value of an element. * * @param keys The text to set, either as a string or an array of strings (which will be joined). * @param elementId The element identifier. * @returns Promise that resolves when the value is replaced. */ async function replaceValue(keys, elementId) { return await this.setElementValue(keys, elementId, true); } /** * Sets the value of an element immediately using ADB input. * * @param keys The text to set, either as a string or an array of strings (which will be joined). * @param elementId The element identifier. * @returns Promise that resolves when the value is set. */ async function setValueImmediate(keys, elementId) { const text = Array.isArray(keys) ? keys.join('') : keys; // first, make sure we are focused on the element await this.click(elementId); // then send through adb await this.adb.inputText(text); } /** * Gets the location of an element relative to the view. * * @param elementId The element identifier. * @returns Promise that resolves to the element's position (x, y coordinates). */ async function getLocationInView(elementId) { return await this.getLocation(elementId); } //# sourceMappingURL=element.js.map