UNPKG

appium-android-driver

Version:

Android UiAutomator and Chrome support for Appium

288 lines 15.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AndroidDriver = void 0; const lodash_1 = __importDefault(require("lodash")); const driver_1 = require("appium/driver"); const constraints_1 = require("./constraints"); const method_map_1 = require("./method-map"); const io_appium_settings_1 = require("io.appium.settings"); const utils_1 = require("./utils"); const helpers_1 = require("./commands/context/helpers"); const exports_1 = require("./commands/context/exports"); const common_1 = require("./commands/device/common"); const emulator_actions_1 = require("./commands/device/emulator-actions"); const emulator_console_1 = require("./commands/device/emulator-console"); const app_management_1 = require("./commands/app-management"); const appearance_1 = require("./commands/appearance"); const deviceidle_1 = require("./commands/deviceidle"); const bluetooth_1 = require("./commands/bluetooth"); const element_1 = require("./commands/element"); const execute_1 = require("./commands/execute"); const file_actions_1 = require("./commands/file-actions"); const find_1 = require("./commands/find"); const geolocation_1 = require("./commands/geolocation"); const gestures_1 = require("./commands/gestures"); const ime_1 = require("./commands/ime"); const intent_1 = require("./commands/intent"); const keyboard_1 = require("./commands/keyboard"); const exports_2 = require("./commands/lock/exports"); const log_1 = require("./commands/log"); const media_projection_1 = require("./commands/media-projection"); const memory_1 = require("./commands/memory"); const nfc_1 = require("./commands/nfc"); const image_injection_1 = require("./commands/image-injection"); const misc_1 = require("./commands/misc"); const network_1 = require("./commands/network"); const performance_1 = require("./commands/performance"); const legacy_1 = require("./commands/legacy"); const permissions_1 = require("./commands/permissions"); const recordscreen_1 = require("./commands/recordscreen"); const resources_1 = require("./commands/resources"); const shell_1 = require("./commands/shell"); const streamscreen_1 = require("./commands/streamscreen"); const system_bars_1 = require("./commands/system-bars"); const time_1 = require("./commands/time"); const execute_method_map_1 = require("./execute-method-map"); const EMULATOR_PATTERN = /\bemulator\b/i; class AndroidDriver extends driver_1.BaseDriver { constructor(opts = {}, shouldValidateCaps = true) { super(opts, shouldValidateCaps); this.getContexts = exports_1.getContexts; this.getCurrentContext = exports_1.getCurrentContext; this.defaultContextName = exports_1.defaultContextName; this.assignContexts = exports_1.assignContexts; this.switchContext = exports_1.switchContext; this.defaultWebviewName = exports_1.defaultWebviewName; this.isChromedriverContext = exports_1.isChromedriverContext; this.startChromedriverProxy = exports_1.startChromedriverProxy; this.stopChromedriverProxies = exports_1.stopChromedriverProxies; this.suspendChromedriverProxy = exports_1.suspendChromedriverProxy; this.startChromeSession = exports_1.startChromeSession; this.onChromedriverStop = exports_1.onChromedriverStop; this.isWebContext = exports_1.isWebContext; this.mobileGetContexts = exports_1.mobileGetContexts; this.setContext = exports_1.setContext; this.setWindow = exports_1.setWindow; this.getWindowHandle = exports_1.getWindowHandle; this.getWindowHandles = exports_1.getWindowHandles; this.notifyBiDiContextChange = exports_1.notifyBiDiContextChange; this.getDeviceInfoFromCaps = common_1.getDeviceInfoFromCaps; this.createADB = common_1.createADB; this.getLaunchInfo = common_1.getLaunchInfo; this.initDevice = common_1.initDevice; this.fingerprint = emulator_actions_1.fingerprint; this.mobileFingerprint = emulator_actions_1.mobileFingerprint; this.sendSMS = emulator_actions_1.sendSMS; this.mobileSendSms = emulator_actions_1.mobileSendSms; this.gsmCall = emulator_actions_1.gsmCall; this.mobileGsmCall = emulator_actions_1.mobileGsmCall; this.gsmSignal = emulator_actions_1.gsmSignal; this.mobileGsmSignal = emulator_actions_1.mobileGsmSignal; this.gsmVoice = emulator_actions_1.gsmVoice; this.mobileGsmVoice = emulator_actions_1.mobileGsmVoice; this.powerAC = emulator_actions_1.powerAC; this.mobilePowerAc = emulator_actions_1.mobilePowerAc; this.powerCapacity = emulator_actions_1.powerCapacity; this.mobilePowerCapacity = emulator_actions_1.mobilePowerCapacity; this.networkSpeed = emulator_actions_1.networkSpeed; this.mobileNetworkSpeed = emulator_actions_1.mobileNetworkSpeed; this.sensorSet = emulator_actions_1.sensorSet; this.mobileExecEmuConsoleCommand = emulator_console_1.mobileExecEmuConsoleCommand; this.getThirdPartyPackages = app_management_1.getThirdPartyPackages; this.uninstallOtherPackages = app_management_1.uninstallOtherPackages; this.installOtherApks = app_management_1.installOtherApks; this.installAUT = app_management_1.installAUT; this.resetAUT = app_management_1.resetAUT; this.background = app_management_1.background; this.getCurrentActivity = app_management_1.getCurrentActivity; this.getCurrentPackage = app_management_1.getCurrentPackage; this.mobileClearApp = app_management_1.mobileClearApp; this.mobileInstallApp = app_management_1.mobileInstallApp; this.installApp = app_management_1.installApp; this.mobileIsAppInstalled = app_management_1.mobileIsAppInstalled; this.mobileRemoveApp = app_management_1.mobileRemoveApp; this.mobileTerminateApp = app_management_1.mobileTerminateApp; this.terminateApp = app_management_1.terminateApp; this.removeApp = app_management_1.removeApp; this.activateApp = app_management_1.activateApp; this.queryAppState = app_management_1.queryAppState; this.isAppInstalled = app_management_1.isAppInstalled; this.mobileBackgroundApp = app_management_1.mobileBackgroundApp; this.mobileGetUiMode = appearance_1.mobileGetUiMode; this.mobileSetUiMode = appearance_1.mobileSetUiMode; this.mobileDeviceidle = deviceidle_1.mobileDeviceidle; this.mobileBluetooth = bluetooth_1.mobileBluetooth; this.getAttribute = element_1.getAttribute; this.getName = element_1.getName; this.elementDisplayed = element_1.elementDisplayed; this.elementEnabled = element_1.elementEnabled; this.elementSelected = element_1.elementSelected; this.setElementValue = element_1.setElementValue; this.doSetElementValue = element_1.doSetElementValue; this.replaceValue = element_1.replaceValue; this.setValueImmediate = element_1.setValueImmediate; this.setValue = element_1.setValue; this.click = element_1.click; this.getLocationInView = element_1.getLocationInView; this.getText = element_1.getText; this.getLocation = element_1.getLocation; this.getSize = element_1.getSize; this.execute = execute_1.execute; this.pullFile = file_actions_1.pullFile; this.pullFolder = file_actions_1.pullFolder; this.pushFile = file_actions_1.pushFile; this.mobileDeleteFile = file_actions_1.mobileDeleteFile; this.findElOrEls = find_1.findElOrEls; this.doFindElementOrEls = find_1.doFindElementOrEls; this.setGeoLocation = geolocation_1.setGeoLocation; this.getGeoLocation = geolocation_1.getGeoLocation; this.mobileRefreshGpsCache = geolocation_1.mobileRefreshGpsCache; this.toggleLocationServices = geolocation_1.toggleLocationServices; this.isLocationServicesEnabled = geolocation_1.isLocationServicesEnabled; this.mobileGetGeolocation = geolocation_1.mobileGetGeolocation; this.mobileSetGeolocation = geolocation_1.mobileSetGeolocation; this.mobileResetGeolocation = geolocation_1.mobileResetGeolocation; this.performActions = gestures_1.performActions; this.isIMEActivated = ime_1.isIMEActivated; this.availableIMEEngines = ime_1.availableIMEEngines; this.getActiveIMEEngine = ime_1.getActiveIMEEngine; this.activateIMEEngine = ime_1.activateIMEEngine; this.deactivateIMEEngine = ime_1.deactivateIMEEngine; this.startActivity = intent_1.startActivity; this.mobileStartActivity = intent_1.mobileStartActivity; this.mobileBroadcast = intent_1.mobileBroadcast; this.mobileStartService = intent_1.mobileStartService; this.mobileStopService = intent_1.mobileStopService; this.hideKeyboard = keyboard_1.hideKeyboard; this.isKeyboardShown = keyboard_1.isKeyboardShown; this.keys = keyboard_1.keys; this.doSendKeys = keyboard_1.doSendKeys; this.pressKeyCode = keyboard_1.pressKeyCode; this.longPressKeyCode = keyboard_1.longPressKeyCode; this.mobilePerformEditorAction = keyboard_1.mobilePerformEditorAction; this.lock = exports_2.lock; this.unlock = exports_2.unlock; this.mobileUnlock = exports_2.mobileUnlock; this.isLocked = exports_2.isLocked; this.supportedLogTypes = log_1.supportedLogTypes; this.mobileStartLogsBroadcast = log_1.mobileStartLogsBroadcast; this.mobileStopLogsBroadcast = log_1.mobileStopLogsBroadcast; this.getLogTypes = log_1.getLogTypes; this.getLog = log_1.getLog; this.assignBiDiLogListener = log_1.assignBiDiLogListener; this.mobileIsMediaProjectionRecordingRunning = media_projection_1.mobileIsMediaProjectionRecordingRunning; this.mobileStartMediaProjectionRecording = media_projection_1.mobileStartMediaProjectionRecording; this.mobileStopMediaProjectionRecording = media_projection_1.mobileStopMediaProjectionRecording; this.mobileSendTrimMemory = memory_1.mobileSendTrimMemory; this.mobileInjectEmulatorCameraImage = image_injection_1.mobileInjectEmulatorCameraImage; this.getWindowRect = misc_1.getWindowRect; this.getWindowSize = misc_1.getWindowSize; this.getDisplayDensity = misc_1.getDisplayDensity; this.mobileGetNotifications = misc_1.mobileGetNotifications; this.mobileListSms = misc_1.mobileListSms; this.openNotifications = misc_1.openNotifications; this.setUrl = misc_1.setUrl; this.getNetworkConnection = network_1.getNetworkConnection; this.isWifiOn = network_1.isWifiOn; this.mobileGetConnectivity = network_1.mobileGetConnectivity; this.mobileSetConnectivity = network_1.mobileSetConnectivity; this.setNetworkConnection = network_1.setNetworkConnection; this.setWifiState = network_1.setWifiState; this.setDataState = network_1.setDataState; this.toggleData = network_1.toggleData; this.toggleFlightMode = network_1.toggleFlightMode; this.toggleWiFi = network_1.toggleWiFi; this.getPerformanceData = performance_1.getPerformanceData; this.getPerformanceDataTypes = performance_1.getPerformanceDataTypes; this.mobileGetPerformanceData = performance_1.mobileGetPerformanceData; this.mobileChangePermissions = permissions_1.mobileChangePermissions; this.mobileGetPermissions = permissions_1.mobileGetPermissions; this.startRecordingScreen = recordscreen_1.startRecordingScreen; this.stopRecordingScreen = recordscreen_1.stopRecordingScreen; this.getStrings = resources_1.getStrings; this.ensureDeviceLocale = resources_1.ensureDeviceLocale; this.mobileShell = shell_1.mobileShell; this.mobileNfc = nfc_1.mobileNfc; this.mobileStartScreenStreaming = streamscreen_1.mobileStartScreenStreaming; this.mobileStopScreenStreaming = streamscreen_1.mobileStopScreenStreaming; this.getSystemBars = system_bars_1.getSystemBars; this.mobilePerformStatusBarCommand = system_bars_1.mobilePerformStatusBarCommand; this.getDeviceTime = time_1.getDeviceTime; this.mobileGetDeviceTime = time_1.mobileGetDeviceTime; this.reset = legacy_1.reset; this.closeApp = legacy_1.closeApp; this.launchApp = legacy_1.launchApp; this.locatorStrategies = [ 'xpath', 'id', 'class name', 'accessibility id', '-android uiautomator', ]; this.desiredCapConstraints = lodash_1.default.cloneDeep(constraints_1.ANDROID_DRIVER_CONSTRAINTS); this.sessionChromedrivers = {}; this.jwpProxyActive = false; this.curContext = this.defaultContextName(); this.opts = opts; this._cachedActivityArgs = {}; // @ts-ignore Remove it after min supported server version is ^2.14.0 this.doesSupportBidi = true; } get settingsApp() { if (!this._settingsApp || this._settingsApp.adb !== this.adb) { this._settingsApp = new io_appium_settings_1.SettingsApp({ adb: this.adb }); } return this._settingsApp; } isEmulator() { const possibleNames = [this.opts?.udid, this.adb?.curDeviceId]; return !!this.opts?.avd || possibleNames.some((x) => EMULATOR_PATTERN.test(String(x))); } get isChromeSession() { return lodash_1.default.includes(Object.keys(helpers_1.CHROME_BROWSER_PACKAGE_ACTIVITY), (this.opts.browserName || '').toLowerCase()); } validateDesiredCaps(caps) { if (!super.validateDesiredCaps(caps)) { return false; } if (caps.browserName) { if (caps.app) { // warn if the capabilities have both `app` and `browser, although this is common with selenium grid this.log.warn(`The desired capabilities should generally not include both an 'app' and a 'browserName'`); } if (caps.appPackage) { throw this.log.errorWithException(`The desired should not include both of an 'appPackage' and a 'browserName'`); } } if (caps.uninstallOtherPackages) { try { (0, utils_1.parseArray)(caps.uninstallOtherPackages); } catch (e) { throw this.log.errorWithException(`Could not parse "uninstallOtherPackages" capability: ${e.message}`); } } return true; } async deleteSession(sessionId) { await utils_1.removeAllSessionWebSocketHandlers.bind(this)(); try { this.adb?.logcat?.removeAllListeners(); await this.adb?.stopLogcat(); } catch (e) { this.log.warn(`Cannot stop the logcat process. Original error: ${e.message}`); } if (this._bidiServerLogListener) { this.log.unwrap().off('log', this._bidiServerLogListener); } await super.deleteSession(sessionId); } } exports.AndroidDriver = AndroidDriver; AndroidDriver.newMethodMap = method_map_1.newMethodMap; AndroidDriver.executeMethodMap = execute_method_map_1.executeMethodMap; //# sourceMappingURL=driver.js.map