appium-android-driver
Version:
Android UiAutomator and Chrome support for Appium
307 lines • 14.5 kB
JavaScript
"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 {
static newMethodMap = method_map_1.newMethodMap;
static executeMethodMap = execute_method_map_1.executeMethodMap;
jwpProxyAvoid;
adb;
_settingsApp;
proxyReqRes;
contexts;
sessionChromedrivers;
chromedriver;
proxyCommand;
jwpProxyActive;
curContext;
useUnlockHelperApp;
defaultIME;
_wasWindowAnimationDisabled;
_cachedActivityArgs;
_screenStreamingProps;
_screenRecordingProperties;
_logcatWebsocketListener;
_bidiServerLogListener;
opts;
constructor(opts = {}, shouldValidateCaps = true) {
super(opts, shouldValidateCaps);
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);
}
getContexts = exports_1.getContexts;
getCurrentContext = exports_1.getCurrentContext;
defaultContextName = exports_1.defaultContextName;
assignContexts = exports_1.assignContexts;
switchContext = exports_1.switchContext;
defaultWebviewName = exports_1.defaultWebviewName;
isChromedriverContext = exports_1.isChromedriverContext;
startChromedriverProxy = exports_1.startChromedriverProxy;
stopChromedriverProxies = exports_1.stopChromedriverProxies;
suspendChromedriverProxy = exports_1.suspendChromedriverProxy;
startChromeSession = exports_1.startChromeSession;
onChromedriverStop = exports_1.onChromedriverStop;
isWebContext = exports_1.isWebContext;
mobileGetContexts = exports_1.mobileGetContexts;
setContext = exports_1.setContext;
setWindow = exports_1.setWindow;
getWindowHandle = exports_1.getWindowHandle;
getWindowHandles = exports_1.getWindowHandles;
notifyBiDiContextChange = exports_1.notifyBiDiContextChange;
getDeviceInfoFromCaps = common_1.getDeviceInfoFromCaps;
createADB = common_1.createADB;
getLaunchInfo = common_1.getLaunchInfo;
initDevice = common_1.initDevice;
fingerprint = emulator_actions_1.fingerprint;
mobileFingerprint = emulator_actions_1.mobileFingerprint;
sendSMS = emulator_actions_1.sendSMS;
mobileSendSms = emulator_actions_1.mobileSendSms;
gsmCall = emulator_actions_1.gsmCall;
mobileGsmCall = emulator_actions_1.mobileGsmCall;
gsmSignal = emulator_actions_1.gsmSignal;
mobileGsmSignal = emulator_actions_1.mobileGsmSignal;
gsmVoice = emulator_actions_1.gsmVoice;
mobileGsmVoice = emulator_actions_1.mobileGsmVoice;
powerAC = emulator_actions_1.powerAC;
mobilePowerAc = emulator_actions_1.mobilePowerAc;
powerCapacity = emulator_actions_1.powerCapacity;
mobilePowerCapacity = emulator_actions_1.mobilePowerCapacity;
networkSpeed = emulator_actions_1.networkSpeed;
mobileNetworkSpeed = emulator_actions_1.mobileNetworkSpeed;
sensorSet = emulator_actions_1.sensorSet;
mobileExecEmuConsoleCommand = emulator_console_1.mobileExecEmuConsoleCommand;
getThirdPartyPackages = app_management_1.getThirdPartyPackages;
uninstallOtherPackages = app_management_1.uninstallOtherPackages;
installOtherApks = app_management_1.installOtherApks;
installAUT = app_management_1.installAUT;
resetAUT = app_management_1.resetAUT;
background = app_management_1.background;
getCurrentActivity = app_management_1.getCurrentActivity;
getCurrentPackage = app_management_1.getCurrentPackage;
mobileClearApp = app_management_1.mobileClearApp;
mobileInstallApp = app_management_1.mobileInstallApp;
installApp = app_management_1.installApp;
mobileIsAppInstalled = app_management_1.mobileIsAppInstalled;
mobileRemoveApp = app_management_1.mobileRemoveApp;
mobileTerminateApp = app_management_1.mobileTerminateApp;
terminateApp = app_management_1.terminateApp;
removeApp = app_management_1.removeApp;
activateApp = app_management_1.activateApp;
queryAppState = app_management_1.queryAppState;
isAppInstalled = app_management_1.isAppInstalled;
mobileBackgroundApp = app_management_1.mobileBackgroundApp;
mobileGetUiMode = appearance_1.mobileGetUiMode;
mobileSetUiMode = appearance_1.mobileSetUiMode;
mobileDeviceidle = deviceidle_1.mobileDeviceidle;
mobileBluetooth = bluetooth_1.mobileBluetooth;
getAttribute = element_1.getAttribute;
getName = element_1.getName;
elementDisplayed = element_1.elementDisplayed;
elementEnabled = element_1.elementEnabled;
elementSelected = element_1.elementSelected;
setElementValue = element_1.setElementValue;
doSetElementValue = element_1.doSetElementValue;
replaceValue = element_1.replaceValue;
setValueImmediate = element_1.setValueImmediate;
setValue = element_1.setValue;
click = element_1.click;
getLocationInView = element_1.getLocationInView;
getText = element_1.getText;
getLocation = element_1.getLocation;
getSize = element_1.getSize;
execute = execute_1.execute;
pullFile = file_actions_1.pullFile;
pullFolder = file_actions_1.pullFolder;
pushFile = file_actions_1.pushFile;
mobileDeleteFile = file_actions_1.mobileDeleteFile;
findElOrEls = find_1.findElOrEls;
doFindElementOrEls = find_1.doFindElementOrEls;
setGeoLocation = geolocation_1.setGeoLocation;
getGeoLocation = geolocation_1.getGeoLocation;
mobileRefreshGpsCache = geolocation_1.mobileRefreshGpsCache;
toggleLocationServices = geolocation_1.toggleLocationServices;
isLocationServicesEnabled = geolocation_1.isLocationServicesEnabled;
mobileGetGeolocation = geolocation_1.mobileGetGeolocation;
mobileSetGeolocation = geolocation_1.mobileSetGeolocation;
mobileResetGeolocation = geolocation_1.mobileResetGeolocation;
performActions = gestures_1.performActions;
isIMEActivated = ime_1.isIMEActivated;
availableIMEEngines = ime_1.availableIMEEngines;
getActiveIMEEngine = ime_1.getActiveIMEEngine;
activateIMEEngine = ime_1.activateIMEEngine;
deactivateIMEEngine = ime_1.deactivateIMEEngine;
startActivity = intent_1.startActivity;
mobileStartActivity = intent_1.mobileStartActivity;
mobileBroadcast = intent_1.mobileBroadcast;
mobileStartService = intent_1.mobileStartService;
mobileStopService = intent_1.mobileStopService;
hideKeyboard = keyboard_1.hideKeyboard;
isKeyboardShown = keyboard_1.isKeyboardShown;
keys = keyboard_1.keys;
doSendKeys = keyboard_1.doSendKeys;
pressKeyCode = keyboard_1.pressKeyCode;
longPressKeyCode = keyboard_1.longPressKeyCode;
mobilePerformEditorAction = keyboard_1.mobilePerformEditorAction;
lock = exports_2.lock;
unlock = exports_2.unlock;
mobileUnlock = exports_2.mobileUnlock;
isLocked = exports_2.isLocked;
supportedLogTypes = log_1.supportedLogTypes;
mobileStartLogsBroadcast = log_1.mobileStartLogsBroadcast;
mobileStopLogsBroadcast = log_1.mobileStopLogsBroadcast;
getLogTypes = log_1.getLogTypes;
getLog = log_1.getLog;
assignBiDiLogListener = log_1.assignBiDiLogListener;
mobileIsMediaProjectionRecordingRunning = media_projection_1.mobileIsMediaProjectionRecordingRunning;
mobileStartMediaProjectionRecording = media_projection_1.mobileStartMediaProjectionRecording;
mobileStopMediaProjectionRecording = media_projection_1.mobileStopMediaProjectionRecording;
mobileSendTrimMemory = memory_1.mobileSendTrimMemory;
mobileInjectEmulatorCameraImage = image_injection_1.mobileInjectEmulatorCameraImage;
getWindowRect = misc_1.getWindowRect;
getWindowSize = misc_1.getWindowSize;
getDisplayDensity = misc_1.getDisplayDensity;
mobileGetNotifications = misc_1.mobileGetNotifications;
mobileListSms = misc_1.mobileListSms;
openNotifications = misc_1.openNotifications;
setUrl = misc_1.setUrl;
getNetworkConnection = network_1.getNetworkConnection;
isWifiOn = network_1.isWifiOn;
mobileGetConnectivity = network_1.mobileGetConnectivity;
mobileSetConnectivity = network_1.mobileSetConnectivity;
setNetworkConnection = network_1.setNetworkConnection;
setWifiState = network_1.setWifiState;
setDataState = network_1.setDataState;
toggleData = network_1.toggleData;
toggleFlightMode = network_1.toggleFlightMode;
toggleWiFi = network_1.toggleWiFi;
getPerformanceData = performance_1.getPerformanceData;
getPerformanceDataTypes = performance_1.getPerformanceDataTypes;
mobileGetPerformanceData = performance_1.mobileGetPerformanceData;
mobileChangePermissions = permissions_1.mobileChangePermissions;
mobileGetPermissions = permissions_1.mobileGetPermissions;
startRecordingScreen = recordscreen_1.startRecordingScreen;
stopRecordingScreen = recordscreen_1.stopRecordingScreen;
getStrings = resources_1.getStrings;
ensureDeviceLocale = resources_1.ensureDeviceLocale;
mobileShell = shell_1.mobileShell;
mobileNfc = nfc_1.mobileNfc;
mobileStartScreenStreaming = streamscreen_1.mobileStartScreenStreaming;
mobileStopScreenStreaming = streamscreen_1.mobileStopScreenStreaming;
getSystemBars = system_bars_1.getSystemBars;
mobilePerformStatusBarCommand = system_bars_1.mobilePerformStatusBarCommand;
getDeviceTime = time_1.getDeviceTime;
mobileGetDeviceTime = time_1.mobileGetDeviceTime;
reset = legacy_1.reset;
closeApp = legacy_1.closeApp;
launchApp = legacy_1.launchApp;
}
exports.AndroidDriver = AndroidDriver;
//# sourceMappingURL=driver.js.map