appium-android-driver 5.10.4 → 5.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/build/lib/android-helpers.js +1 -1
- package/build/lib/android-helpers.js.map +1 -1
- package/build/lib/bootstrap.js +1 -1
- package/build/lib/bootstrap.js.map +1 -1
- package/build/lib/commands/actions.js +52 -1
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.js +1 -1
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-management.js +1 -1
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/context.js +1 -1
- package/build/lib/commands/context.js.map +1 -1
- package/build/lib/commands/execute.js +1 -1
- package/build/lib/commands/execute.js.map +1 -1
- package/build/lib/commands/file-actions.js +1 -1
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/find.js +1 -1
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.js +1 -1
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/ime.js +1 -1
- package/build/lib/commands/ime.js.map +1 -1
- package/build/lib/commands/index.js +1 -1
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/intent.js +1 -1
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/keyboard.js +1 -1
- package/build/lib/commands/keyboard.js.map +1 -1
- package/build/lib/commands/log.js +1 -1
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-projection.js +1 -1
- package/build/lib/commands/media-projection.js.map +1 -1
- package/build/lib/commands/network.js +6 -55
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/commands/performance.js +1 -1
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.js +1 -1
- package/build/lib/commands/permissions.js.map +1 -1
- package/build/lib/commands/recordscreen.js +1 -1
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/streamscreen.js +1 -1
- package/build/lib/commands/streamscreen.js.map +1 -1
- package/build/lib/commands/touch.js +1 -1
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/driver.js +1 -1
- package/build/lib/driver.js.map +1 -1
- package/build/lib/uiautomator.js +1 -1
- package/build/lib/uiautomator.js.map +1 -1
- package/build/lib/unlock-helpers.js +1 -1
- package/build/lib/unlock-helpers.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lib/webview-helpers.js +1 -1
- package/build/lib/webview-helpers.js.map +1 -1
- package/lib/commands/actions.js +135 -0
- package/lib/commands/network.js +18 -90
- package/lib/utils.js +4 -3
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webview-helpers.js","names":["_lodash","_interopRequireDefault","require","_logger","_axios","_support","_portscanner","_lruCache","_bluebird","_path","_os","NATIVE_WIN","exports","WEBVIEW_WIN","CHROMIUM_WIN","WEBVIEW_BASE","WEBVIEW_PID_PATTERN","RegExp","WEBVIEW_PKG_PATTERN","DEVTOOLS_SOCKET_PATTERN","CROSSWALK_SOCKET_PATTERN","CHROMIUM_DEVTOOLS_SOCKET","CHROME_PACKAGE_NAME","KNOWN_CHROME_PACKAGE_NAMES","DEVTOOLS_PORTS_RANGE","WEBVIEWS_DETAILS_CACHE","LRU","max","updateAgeOnGet","CDP_REQ_TIMEOUT","DEVTOOLS_PORT_ALLOCATION_GUARD","util","getLockFileGuard","path","resolve","os","tmpdir","timeout","tryRecovery","helpers","toDetailsCacheKey","adb","webview","curDeviceId","getPotentialWebviewProcs","out","shell","names","allMatches","line","split","flags","st","sockPath","trim","startsWith","push","test","_","isEmpty","logger","debug","JSON","stringify","length","pluralize","uniq","webviewsFromProcs","deviceSocket","socketNames","webviews","socketName","proc","socketNameMatch","exec","crosswalkMatch","allocateDevtoolsPort","webviewDevtoolsPort","remotePort","replace","startPort","endPort","localPort","findAPortNotInUse","e","Error","adbExec","collectWebviewsDetails","webviewsMapping","opts","ensureWebviewsHavePages","enableWebviewDetailsCollection","info","detailCollectors","item","cdpInfo","pages","cdpList","removePortForward","B","all","axios","url","data","procFromWebview","pidMatch","pid","pkg","getNameByPid","parseWebviewNames","isChromeSession","result","webviewName","getWebViewsMapping","androidDeviceSocket","webviewMapping","wvName","process","undefined","pkgMatch","name","id","warn","message","key","set","has","delete","getWebviewDetails","get","createChromedriverCaps","deviceId","webViewDetails","_opts$chromeOptions","_webViewDetails$info","_webViewDetails$proce","_webViewDetails$proce2","_opts$chromeOptions2","caps","chromeOptions","androidPackage","appPackage","isBoolean","chromeUseRunningApp","androidUseRunningApp","chromeAndroidPackage","chromeAndroidActivity","androidActivity","chromeAndroidProcess","androidProcess","toLower","browserName","appActivity","pageLoadStrategy","isChrome","includes","androidDeviceSerial","isPlainObject","loggingPrefs","chromeLoggingPrefs","enablePerformanceLogging","newPref","performance","Object","assign","Arguments","args","protectedCapNames","opt","val","toPairs","isUndefined","optName","_default","default"],"sources":["../../lib/webview-helpers.js"],"sourcesContent":["import _ from 'lodash';\nimport logger from './logger';\nimport axios from 'axios';\nimport { util } from '@appium/support';\nimport { findAPortNotInUse } from 'portscanner';\nimport LRU from 'lru-cache';\nimport B from 'bluebird';\nimport path from 'path';\nimport os from 'os';\n\nconst NATIVE_WIN = 'NATIVE_APP';\nconst WEBVIEW_WIN = 'WEBVIEW';\nconst CHROMIUM_WIN = 'CHROMIUM';\nconst WEBVIEW_BASE = `${WEBVIEW_WIN}_`;\nconst WEBVIEW_PID_PATTERN = new RegExp(`^${WEBVIEW_BASE}(\\\\d+)`);\nconst WEBVIEW_PKG_PATTERN = new RegExp(`^${WEBVIEW_BASE}([^\\\\d\\\\s][\\\\w.]*)`);\nconst DEVTOOLS_SOCKET_PATTERN = /@[\\w.]+_devtools_remote_?(\\d+)?\\b/;\nconst CROSSWALK_SOCKET_PATTERN = /@([\\w.]+)_devtools_remote\\b/;\nconst CHROMIUM_DEVTOOLS_SOCKET = 'chrome_devtools_remote';\nconst CHROME_PACKAGE_NAME = 'com.android.chrome';\nconst KNOWN_CHROME_PACKAGE_NAMES = [\n CHROME_PACKAGE_NAME,\n 'com.chrome.beta',\n 'com.chrome.dev',\n 'com.chrome.canary',\n];\nconst DEVTOOLS_PORTS_RANGE = [10900, 11000];\nconst WEBVIEWS_DETAILS_CACHE = new LRU({\n max: 100,\n updateAgeOnGet: true,\n});\nconst CDP_REQ_TIMEOUT = 2000; // ms\nconst DEVTOOLS_PORT_ALLOCATION_GUARD = util.getLockFileGuard(\n path.resolve(os.tmpdir(), 'android_devtools_port_guard'),\n {timeout: 7, tryRecovery: true}\n);\n\nconst helpers = {};\n\nfunction toDetailsCacheKey (adb, webview) {\n return `${adb?.curDeviceId}:${webview}`;\n}\n\n/**\n * This function gets a list of android system processes and returns ones\n * that look like webviews\n * See https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc\n * for more details\n *\n * @param {object} adb - an ADB instance\n *\n * @return {Array.<string>} - a list of matching webview socket names (including the leading '@')\n */\nasync function getPotentialWebviewProcs (adb) {\n const out = await adb.shell(['cat', '/proc/net/unix']);\n const names = [];\n const allMatches = [];\n for (const line of out.split('\\n')) {\n // Num RefCount Protocol Flags Type St Inode Path\n const [,,, flags,, st,, sockPath] = line.trim().split(/\\s+/);\n if (!sockPath) {\n continue;\n }\n if (sockPath.startsWith('@')) {\n allMatches.push(line.trim());\n }\n if (flags !== '00010000' || st !== '01') {\n continue;\n }\n if (!DEVTOOLS_SOCKET_PATTERN.test(sockPath)) {\n continue;\n }\n\n names.push(sockPath);\n }\n if (_.isEmpty(names)) {\n logger.debug('Found no active devtools sockets');\n if (!_.isEmpty(allMatches)) {\n logger.debug(`Other sockets are: ${JSON.stringify(allMatches, null, 2)}`);\n }\n } else {\n logger.debug(`Parsed ${names.length} active devtools ${util.pluralize('socket', names.length, false)}: ` +\n JSON.stringify(names));\n }\n // sometimes the webview process shows up multiple times per app\n return _.uniq(names);\n}\n\n/**\n * @typedef {Object} WebviewProc\n * @property {string} proc - The webview process name (as returned by\n * getPotentialWebviewProcs\n * @property {string} webview - The actual webview context name\n */\n/**\n * This function retrieves a list of system processes that look like webviews,\n * and returns them along with the webview context name appropriate for it.\n * If we pass in a deviceSocket, we only attempt to find webviews which match\n * that socket name (this is for apps which embed Chromium, which isn't the\n * same as chrome-backed webviews).\n *\n * @param {object} adb - an ADB instance\n * @param {?string} deviceSocket - the explictly-named device socket to use\n *\n * @return {Array.<WebviewProc>}\n */\nasync function webviewsFromProcs (adb, deviceSocket = null) {\n const socketNames = await getPotentialWebviewProcs(adb);\n const webviews = [];\n for (const socketName of socketNames) {\n if (deviceSocket === CHROMIUM_DEVTOOLS_SOCKET && socketName === `@${deviceSocket}`) {\n webviews.push({\n proc: socketName,\n webview: CHROMIUM_WIN,\n });\n continue;\n }\n\n const socketNameMatch = DEVTOOLS_SOCKET_PATTERN.exec(socketName);\n if (!socketNameMatch) {\n continue;\n }\n const crosswalkMatch = CROSSWALK_SOCKET_PATTERN.exec(socketName);\n if (!socketNameMatch[1] && !crosswalkMatch) {\n continue;\n }\n\n if (deviceSocket && socketName === `@${deviceSocket}` || !deviceSocket) {\n webviews.push({\n proc: socketName,\n webview: socketNameMatch[1]\n ? `${WEBVIEW_BASE}${socketNameMatch[1]}`\n : `${WEBVIEW_BASE}${crosswalkMatch[1]}`,\n });\n }\n }\n return webviews;\n}\n\n/**\n * Allocates a local port for devtools communication\n *\n * @param {ADB} adb ADB instance\n * @param {string} socketName The remote Unix socket name\n * @param {?number} webviewDevtoolsPort The local port number or null to apply\n * autodetection\n * @returns {number} The local port number if the remote socket has been forwarded\n * successfully or `null` otherwise\n * @throws {Error} If there was an error while allocating the local port\n */\nasync function allocateDevtoolsPort (adb, socketName, webviewDevtoolsPort = null) {\n // socket names come with '@', but this should not be a part of the abstract\n // remote port, so remove it\n const remotePort = socketName.replace(/^@/, '');\n let [startPort, endPort] = DEVTOOLS_PORTS_RANGE;\n if (webviewDevtoolsPort) {\n endPort = webviewDevtoolsPort + (endPort - startPort);\n startPort = webviewDevtoolsPort;\n }\n logger.debug(`Forwarding remote port ${remotePort} to a local ` +\n `port in range ${startPort}..${endPort}`);\n if (!webviewDevtoolsPort) {\n logger.debug(`You could use the 'webviewDevtoolsPort' capability to customize ` +\n `the starting port number`);\n }\n return await DEVTOOLS_PORT_ALLOCATION_GUARD(async () => {\n let localPort;\n try {\n localPort = await findAPortNotInUse(startPort, endPort);\n } catch (e) {\n throw new Error(`Cannot find any free port to forward the Devtools socket ` +\n `in range ${startPort}..${endPort}. You could set the starting port number ` +\n `manually by providing the 'webviewDevtoolsPort' capability`);\n }\n await adb.adbExec(['forward', `tcp:${localPort}`, `localabstract:${remotePort}`]);\n return localPort;\n });\n}\n\n/**\n * @typedef {Object} WebviewProps\n * @property {string} proc The name of the Devtools Unix socket\n * @property {string} webview The web view alias. Looks like `WEBVIEW_`\n * prefix plus PID or package name\n * @property {?Object} info Webview information as it is retrieved by\n * /json/version CDP endpoint\n * @property {?Array<Object>} pages Webview pages list as it is retrieved by\n * /json/list CDP endpoint\n */\n\n/**\n * @typedef {Object} DetailCollectionOptions\n * @property {?string|number} webviewDevtoolsPort The starting port to use for webview page\n * presence check (if not the default of 9222).\n * @property {?boolean} ensureWebviewsHavePages Whether to check for webview\n * pages presence\n * @property {boolean} enableWebviewDetailsCollection Whether to collect\n * web view details and send them to Chromedriver constructor, so it could\n * select a binary more precisely based on this info.\n */\n\n/**\n * This is a wrapper for Chrome Debugger Protocol data collection.\n * No error is thrown if CDP request fails - in such case no data will be\n * recorded into the corresponding `webviewsMapping` item.\n *\n * @param {ADB} adb The ADB instance\n * @param {Array<WebviewProps>} webviewsMapping The current webviews mapping\n * !!! Each item of this array gets mutated (`info`/`pages` properties get added\n * based on the provided `opts`) if the requested details have been\n * successfully retrieved for it !!!\n * @param {DetailCollectionOptions} opts If both `ensureWebviewsHavePages` and\n * `enableWebviewDetailsCollection` properties are falsy then no details collection\n * is performed\n */\nasync function collectWebviewsDetails (adb, webviewsMapping, opts = {}) {\n if (_.isEmpty(webviewsMapping)) {\n return;\n }\n\n const {\n webviewDevtoolsPort = null,\n ensureWebviewsHavePages = null,\n enableWebviewDetailsCollection = null,\n } = opts;\n\n if (!ensureWebviewsHavePages) {\n logger.info(`Not checking whether webviews have active pages; use the ` +\n `'ensureWebviewsHavePages' cap to turn this check on`);\n }\n\n if (!enableWebviewDetailsCollection) {\n logger.info(`Not collecting web view details. Details collection might help ` +\n `to make Chromedriver initialization more precise. Use the 'enableWebviewDetailsCollection' ` +\n `cap to turn it on`);\n }\n\n if (!ensureWebviewsHavePages && !enableWebviewDetailsCollection) {\n return;\n }\n\n // Connect to each devtools socket and retrieve web view details\n logger.debug(`Collecting CDP data of ${util.pluralize('webview', webviewsMapping.length, true)}`);\n const detailCollectors = [];\n for (const item of webviewsMapping) {\n detailCollectors.push((async () => {\n let localPort;\n try {\n localPort = await allocateDevtoolsPort(adb, item.proc, webviewDevtoolsPort);\n if (enableWebviewDetailsCollection) {\n item.info = await cdpInfo(localPort);\n }\n if (ensureWebviewsHavePages) {\n item.pages = await cdpList(localPort);\n }\n } catch (e) {\n logger.debug(e);\n } finally {\n if (localPort) {\n try {\n await adb.removePortForward(localPort);\n } catch (e) {\n logger.debug(e);\n }\n }\n }\n })());\n }\n await B.all(detailCollectors);\n logger.debug(`CDP data collection completed`);\n}\n\n// https://chromedevtools.github.io/devtools-protocol/\nasync function cdpList (localPort) {\n return (await axios({\n url: `http://127.0.0.1:${localPort}/json/list`,\n timeout: CDP_REQ_TIMEOUT,\n })).data;\n}\n\n// https://chromedevtools.github.io/devtools-protocol/\nasync function cdpInfo (localPort) {\n return (await axios({\n url: `http://127.0.0.1:${localPort}/json/version`,\n timeout: CDP_REQ_TIMEOUT,\n })).data;\n}\n\n/**\n * Take a webview name like WEBVIEW_4296 and use 'adb shell ps' to figure out\n * which app package is associated with that webview. One of the reasons we\n * want to do this is to make sure we're listing webviews for the actual AUT,\n * not some other running app\n *\n * @param {object} adb - an ADB instance\n * @param {string} webview - a webview process name\n *\n * @returns {string} - the package name of the app running the webview\n * @throws {Error} If there was a failure while retrieving the process name\n */\nhelpers.procFromWebview = async function procFromWebview (adb, webview) {\n const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);\n if (!pidMatch) {\n throw new Error(`Could not find PID for webview '${webview}'`);\n }\n\n const pid = pidMatch[1];\n logger.debug(`${webview} mapped to pid ${pid}`);\n logger.debug(`Getting process name for webview '${webview}'`);\n const pkg = await adb.getNameByPid(pid);\n logger.debug(`Got process name: '${pkg}'`);\n return pkg;\n};\n\n/**\n * Parse webview names for getContexts\n *\n * @param {Array<WebviewsMapping>} webviewsMapping See note on getWebViewsMapping\n * @param {GetWebviewsOpts} opts See note on getWebViewsMapping\n * @return {Array.<string>} - a list of webview names\n */\nhelpers.parseWebviewNames = function parseWebviewNames (webviewsMapping, {\n ensureWebviewsHavePages = true,\n isChromeSession = false\n} = {}) {\n if (isChromeSession) {\n return [CHROMIUM_WIN];\n }\n\n const result = [];\n for (const {webview, pages, proc, webviewName} of webviewsMapping) {\n if (ensureWebviewsHavePages && pages?.length === 0) {\n logger.info(`Skipping the webview '${webview}' at '${proc}' ` +\n `since it has reported having zero pages`);\n continue;\n }\n if (webviewName) {\n result.push(webviewName);\n }\n }\n logger.debug(`Found ${util.pluralize('webview', result.length, true)}: ${JSON.stringify(result)}`);\n return result;\n};\n\n/**\n * @typedef {Object} GetWebviewsOpts\n * @property {string} androidDeviceSocket [null] - device socket name\n * @property {boolean} ensureWebviewsHavePages [true] - whether to check for webview\n * page presence\n * @property {number} webviewDevtoolsPort [9222] - port to use for webview page\n * presence check.\n * @property {boolean} enableWebviewDetailsCollection [true] - whether to collect\n * web view details and send them to Chromedriver constructor, so it could\n * select a binary more precisely based on this info.\n */\n\n/**\n * @typedef {Object} WebviewsMapping\n * @property {string} proc See note on WebviewProps\n * @property {string} webview See note on WebviewProps\n * @property {?Object} info See note on WebviewProps\n * @property {?Array<Object>} pages See note on WebviewProps\n * @propery {?string} webviewName An actual webview name for switching context\n */\n\n/**\n * Get a list of available webviews mapping by introspecting processes with adb,\n * where webviews are listed. It's possible to pass in a 'deviceSocket' arg, which\n * limits the webview possibilities to the one running on the Chromium devtools\n * socket we're interested in (see note on webviewsFromProcs). We can also\n * direct this method to verify whether a particular webview process actually\n * has any pages (if a process exists but no pages are found, Chromedriver will\n * not actually be able to connect to it, so this serves as a guard for that\n * strange failure mode). The strategy for checking whether any pages are\n * active involves sending a request to the remote debug server on the device,\n * hence it is also possible to specify the port on the host machine which\n * should be used for this communication.\n *\n * @param {object} adb - an ADB instance\n * @param {GetWebviewsOpts} opts\n *\n * @return {Array<WebviewsMapping>} webviewsMapping\n */\nhelpers.getWebViewsMapping = async function getWebViewsMapping (adb, {\n androidDeviceSocket = null,\n ensureWebviewsHavePages = true,\n webviewDevtoolsPort = null,\n enableWebviewDetailsCollection = true\n} = {}) {\n logger.debug('Getting a list of available webviews');\n const webviewsMapping = await webviewsFromProcs(adb, androidDeviceSocket);\n\n await collectWebviewsDetails(adb, webviewsMapping, {\n ensureWebviewsHavePages,\n enableWebviewDetailsCollection,\n webviewDevtoolsPort,\n });\n\n for (const webviewMapping of webviewsMapping) {\n const {webview, info} = webviewMapping;\n webviewMapping.webviewName = null;\n\n let wvName = webview;\n let process = undefined;\n if (!androidDeviceSocket) {\n const pkgMatch = WEBVIEW_PKG_PATTERN.exec(webview);\n try {\n // web view name could either be suffixed with PID or the package name\n // package names could not start with a digit\n const pkg = pkgMatch ? pkgMatch[1] : await helpers.procFromWebview(adb, webview);\n wvName = `${WEBVIEW_BASE}${pkg}`;\n const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);\n process = {\n name: pkg,\n id: pidMatch ? pidMatch[1] : null,\n };\n } catch (e) {\n logger.warn(e.message);\n continue;\n }\n }\n\n webviewMapping.webviewName = wvName;\n const key = toDetailsCacheKey(adb, wvName);\n if (info || process) {\n WEBVIEWS_DETAILS_CACHE.set(key, { info, process });\n } else if (WEBVIEWS_DETAILS_CACHE.has(key)) {\n WEBVIEWS_DETAILS_CACHE.delete(key);\n }\n }\n return webviewsMapping;\n};\n\n/**\n * @typedef {Object} ProcessInfo\n * @property {string} name The process name\n * @property {?string} id The process id (if could be retrieved)\n */\n\n/**\n * @typedef {Object} WebViewDetails\n * @property {?ProcessInfo} process - Web view process details\n * @property {Object} info - Web view details as returned by /json/version CDP endpoint, for example:\n * {\n * \"Browser\": \"Chrome/72.0.3601.0\",\n * \"Protocol-Version\": \"1.3\",\n * \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3601.0 Safari/537.36\",\n * \"V8-Version\": \"7.2.233\",\n * \"WebKit-Version\": \"537.36 (@cfede9db1d154de0468cb0538479f34c0755a0f4)\",\n * \"webSocketDebuggerUrl\": \"ws://localhost:9222/devtools/browser/b0b8a4fb-bb17-4359-9533-a8d9f3908bd8\"\n * }\n */\n\n/**\n * Retrieves web view details previously cached by `getWebviews` call\n *\n * @param {ADB} adb ADB instance\n * @param {string} webview The name of the web view\n * @returns {?WebViewDetails} Either `undefined` or the recent web view details\n */\nhelpers.getWebviewDetails = function getWebviewDetails (adb, webview) {\n const key = toDetailsCacheKey(adb, webview);\n return WEBVIEWS_DETAILS_CACHE.get(key);\n};\n\n/**\n * Create Chrome driver capabilities based on the provided\n * Appium capabilities\n *\n * @param {Object} opts User-provided capabilities object\n * @param {string} deviceId The identifier of the Android device under test\n * @param {?WebViewDetails} webViewDetails\n * @returns {Object} The capabilities object.\n * See https://chromedriver.chromium.org/capabilities for more details.\n */\nhelpers.createChromedriverCaps = function createChromedriverCaps (opts, deviceId, webViewDetails) {\n const caps = { chromeOptions: {} };\n\n const androidPackage = opts.chromeOptions?.androidPackage\n || opts.appPackage\n || webViewDetails?.info?.['Android-Package'];\n if (androidPackage) {\n // chromedriver raises an invalid argument error when androidPackage is 'null'\n caps.chromeOptions.androidPackage = androidPackage;\n }\n if (_.isBoolean(opts.chromeUseRunningApp)) {\n caps.chromeOptions.androidUseRunningApp = opts.chromeUseRunningApp;\n }\n if (opts.chromeAndroidPackage) {\n caps.chromeOptions.androidPackage = opts.chromeAndroidPackage;\n }\n if (opts.chromeAndroidActivity) {\n caps.chromeOptions.androidActivity = opts.chromeAndroidActivity;\n }\n if (opts.chromeAndroidProcess) {\n caps.chromeOptions.androidProcess = opts.chromeAndroidProcess;\n } else if (webViewDetails?.process?.name && webViewDetails?.process?.id) {\n caps.chromeOptions.androidProcess = webViewDetails.process.name;\n }\n if (_.toLower(opts.browserName) === 'chromium-webview') {\n caps.chromeOptions.androidActivity = opts.appActivity;\n }\n if (opts.pageLoadStrategy) {\n caps.pageLoadStrategy = opts.pageLoadStrategy;\n }\n const isChrome = _.toLower(caps.chromeOptions.androidPackage) === 'chrome';\n if (_.includes(KNOWN_CHROME_PACKAGE_NAMES, caps.chromeOptions.androidPackage) || isChrome) {\n // if we have extracted package from context name, it could come in as bare\n // \"chrome\", and so we should make sure the details are correct, including\n // not using an activity or process id\n if (isChrome) {\n caps.chromeOptions.androidPackage = CHROME_PACKAGE_NAME;\n }\n delete caps.chromeOptions.androidActivity;\n delete caps.chromeOptions.androidProcess;\n }\n // add device id from adb\n caps.chromeOptions.androidDeviceSerial = deviceId;\n\n if (_.isPlainObject(opts.loggingPrefs) || _.isPlainObject(opts.chromeLoggingPrefs)) {\n if (opts.loggingPrefs) {\n logger.warn(`The 'loggingPrefs' cap is deprecated; use the 'chromeLoggingPrefs' cap instead`);\n }\n caps.loggingPrefs = opts.chromeLoggingPrefs || opts.loggingPrefs;\n }\n if (opts.enablePerformanceLogging) {\n logger.warn(`The 'enablePerformanceLogging' cap is deprecated; simply use ` +\n `the 'chromeLoggingPrefs' cap instead, with a 'performance' key set to 'ALL'`);\n const newPref = {performance: 'ALL'};\n // don't overwrite other logging prefs that have been sent in if they exist\n caps.loggingPrefs = caps.loggingPrefs\n ? Object.assign({}, caps.loggingPrefs, newPref)\n : newPref;\n }\n\n if (opts.chromeOptions?.Arguments) {\n // merge `Arguments` and `args`\n opts.chromeOptions.args = [...(opts.chromeOptions.args || []), ...opts.chromeOptions.Arguments];\n delete opts.chromeOptions.Arguments;\n }\n\n logger.debug('Precalculated Chromedriver capabilities: ' +\n JSON.stringify(caps.chromeOptions, null, 2));\n\n const protectedCapNames = [];\n for (const [opt, val] of _.toPairs(opts.chromeOptions)) {\n if (_.isUndefined(caps.chromeOptions[opt])) {\n caps.chromeOptions[opt] = val;\n } else {\n protectedCapNames.push(opt);\n }\n }\n if (!_.isEmpty(protectedCapNames)) {\n logger.info('The following Chromedriver capabilities cannot be overridden ' +\n 'by the provided chromeOptions:');\n for (const optName of protectedCapNames) {\n logger.info(` ${optName} (${JSON.stringify(opts.chromeOptions[optName])})`);\n }\n }\n\n return caps;\n};\n\nexport default helpers;\nexport { helpers, NATIVE_WIN, WEBVIEW_WIN, WEBVIEW_BASE, CHROMIUM_WIN, KNOWN_CHROME_PACKAGE_NAMES };\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,KAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,GAAA,GAAAT,sBAAA,CAAAC,OAAA;AAEA,MAAMS,UAAU,GAAG,YAAY;AAACC,OAAA,CAAAD,UAAA,GAAAA,UAAA;AAChC,MAAME,WAAW,GAAG,SAAS;AAACD,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAC9B,MAAMC,YAAY,GAAG,UAAU;AAACF,OAAA,CAAAE,YAAA,GAAAA,Y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AAC;IACnC,KAAK,MAAMgF,OAAO,IAAIL,iBAAiB,EAAE;MACvC3G,eAAM,CAACgC,IAAI,CAAE,KAAIgF,OAAQ,KAAI9G,IAAI,CAACC,SAAS,CAAC0B,IAAI,CAACkD,aAAa,CAACiC,OAAO,CAAC,CAAE,GAAE,CAAC;IAC9E;EACF;EAEA,OAAOlC,IAAI;AACb,CAAC;AAAC,IAAAmC,QAAA,GAEatI,OAAO;AAAA3B,OAAA,CAAAkK,OAAA,GAAAD,QAAA"}
|
|
1
|
+
{"version":3,"file":"webview-helpers.js","names":["_lodash","_interopRequireDefault","require","_logger","_axios","_support","_portscanner","_lruCache","_bluebird","_path","_os","NATIVE_WIN","exports","WEBVIEW_WIN","CHROMIUM_WIN","WEBVIEW_BASE","WEBVIEW_PID_PATTERN","RegExp","WEBVIEW_PKG_PATTERN","DEVTOOLS_SOCKET_PATTERN","CROSSWALK_SOCKET_PATTERN","CHROMIUM_DEVTOOLS_SOCKET","CHROME_PACKAGE_NAME","KNOWN_CHROME_PACKAGE_NAMES","DEVTOOLS_PORTS_RANGE","WEBVIEWS_DETAILS_CACHE","LRU","max","updateAgeOnGet","CDP_REQ_TIMEOUT","DEVTOOLS_PORT_ALLOCATION_GUARD","util","getLockFileGuard","path","resolve","os","tmpdir","timeout","tryRecovery","helpers","toDetailsCacheKey","adb","webview","curDeviceId","getPotentialWebviewProcs","out","shell","names","allMatches","line","split","flags","st","sockPath","trim","startsWith","push","test","_","isEmpty","logger","debug","JSON","stringify","length","pluralize","uniq","webviewsFromProcs","deviceSocket","socketNames","webviews","socketName","proc","socketNameMatch","exec","crosswalkMatch","allocateDevtoolsPort","webviewDevtoolsPort","remotePort","replace","startPort","endPort","localPort","findAPortNotInUse","e","Error","adbExec","collectWebviewsDetails","webviewsMapping","opts","ensureWebviewsHavePages","enableWebviewDetailsCollection","info","detailCollectors","item","cdpInfo","pages","cdpList","removePortForward","B","all","axios","url","data","procFromWebview","pidMatch","pid","pkg","getNameByPid","parseWebviewNames","isChromeSession","result","webviewName","getWebViewsMapping","androidDeviceSocket","webviewMapping","wvName","process","undefined","pkgMatch","name","id","warn","message","key","set","has","delete","getWebviewDetails","get","createChromedriverCaps","deviceId","webViewDetails","_opts$chromeOptions","_webViewDetails$info","_webViewDetails$proce","_webViewDetails$proce2","_opts$chromeOptions2","caps","chromeOptions","androidPackage","appPackage","isBoolean","chromeUseRunningApp","androidUseRunningApp","chromeAndroidPackage","chromeAndroidActivity","androidActivity","chromeAndroidProcess","androidProcess","toLower","browserName","appActivity","pageLoadStrategy","isChrome","includes","androidDeviceSerial","isPlainObject","loggingPrefs","chromeLoggingPrefs","enablePerformanceLogging","newPref","performance","Object","assign","Arguments","args","protectedCapNames","opt","val","toPairs","isUndefined","optName","_default","default"],"sources":["../../lib/webview-helpers.js"],"sourcesContent":["import _ from 'lodash';\nimport logger from './logger';\nimport axios from 'axios';\nimport { util } from '@appium/support';\nimport { findAPortNotInUse } from 'portscanner';\nimport LRU from 'lru-cache';\nimport B from 'bluebird';\nimport path from 'path';\nimport os from 'os';\n\nconst NATIVE_WIN = 'NATIVE_APP';\nconst WEBVIEW_WIN = 'WEBVIEW';\nconst CHROMIUM_WIN = 'CHROMIUM';\nconst WEBVIEW_BASE = `${WEBVIEW_WIN}_`;\nconst WEBVIEW_PID_PATTERN = new RegExp(`^${WEBVIEW_BASE}(\\\\d+)`);\nconst WEBVIEW_PKG_PATTERN = new RegExp(`^${WEBVIEW_BASE}([^\\\\d\\\\s][\\\\w.]*)`);\nconst DEVTOOLS_SOCKET_PATTERN = /@[\\w.]+_devtools_remote_?(\\d+)?\\b/;\nconst CROSSWALK_SOCKET_PATTERN = /@([\\w.]+)_devtools_remote\\b/;\nconst CHROMIUM_DEVTOOLS_SOCKET = 'chrome_devtools_remote';\nconst CHROME_PACKAGE_NAME = 'com.android.chrome';\nconst KNOWN_CHROME_PACKAGE_NAMES = [\n CHROME_PACKAGE_NAME,\n 'com.chrome.beta',\n 'com.chrome.dev',\n 'com.chrome.canary',\n];\nconst DEVTOOLS_PORTS_RANGE = [10900, 11000];\nconst WEBVIEWS_DETAILS_CACHE = new LRU({\n max: 100,\n updateAgeOnGet: true,\n});\nconst CDP_REQ_TIMEOUT = 2000; // ms\nconst DEVTOOLS_PORT_ALLOCATION_GUARD = util.getLockFileGuard(\n path.resolve(os.tmpdir(), 'android_devtools_port_guard'),\n {timeout: 7, tryRecovery: true}\n);\n\nconst helpers = {};\n\nfunction toDetailsCacheKey (adb, webview) {\n return `${adb?.curDeviceId}:${webview}`;\n}\n\n/**\n * This function gets a list of android system processes and returns ones\n * that look like webviews\n * See https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc\n * for more details\n *\n * @param {object} adb - an ADB instance\n *\n * @return {Array.<string>} - a list of matching webview socket names (including the leading '@')\n */\nasync function getPotentialWebviewProcs (adb) {\n const out = await adb.shell(['cat', '/proc/net/unix']);\n const names = [];\n const allMatches = [];\n for (const line of out.split('\\n')) {\n // Num RefCount Protocol Flags Type St Inode Path\n const [,,, flags,, st,, sockPath] = line.trim().split(/\\s+/);\n if (!sockPath) {\n continue;\n }\n if (sockPath.startsWith('@')) {\n allMatches.push(line.trim());\n }\n if (flags !== '00010000' || st !== '01') {\n continue;\n }\n if (!DEVTOOLS_SOCKET_PATTERN.test(sockPath)) {\n continue;\n }\n\n names.push(sockPath);\n }\n if (_.isEmpty(names)) {\n logger.debug('Found no active devtools sockets');\n if (!_.isEmpty(allMatches)) {\n logger.debug(`Other sockets are: ${JSON.stringify(allMatches, null, 2)}`);\n }\n } else {\n logger.debug(`Parsed ${names.length} active devtools ${util.pluralize('socket', names.length, false)}: ` +\n JSON.stringify(names));\n }\n // sometimes the webview process shows up multiple times per app\n return _.uniq(names);\n}\n\n/**\n * @typedef {Object} WebviewProc\n * @property {string} proc - The webview process name (as returned by\n * getPotentialWebviewProcs\n * @property {string} webview - The actual webview context name\n */\n/**\n * This function retrieves a list of system processes that look like webviews,\n * and returns them along with the webview context name appropriate for it.\n * If we pass in a deviceSocket, we only attempt to find webviews which match\n * that socket name (this is for apps which embed Chromium, which isn't the\n * same as chrome-backed webviews).\n *\n * @param {object} adb - an ADB instance\n * @param {?string} deviceSocket - the explictly-named device socket to use\n *\n * @return {Array.<WebviewProc>}\n */\nasync function webviewsFromProcs (adb, deviceSocket = null) {\n const socketNames = await getPotentialWebviewProcs(adb);\n const webviews = [];\n for (const socketName of socketNames) {\n if (deviceSocket === CHROMIUM_DEVTOOLS_SOCKET && socketName === `@${deviceSocket}`) {\n webviews.push({\n proc: socketName,\n webview: CHROMIUM_WIN,\n });\n continue;\n }\n\n const socketNameMatch = DEVTOOLS_SOCKET_PATTERN.exec(socketName);\n if (!socketNameMatch) {\n continue;\n }\n const crosswalkMatch = CROSSWALK_SOCKET_PATTERN.exec(socketName);\n if (!socketNameMatch[1] && !crosswalkMatch) {\n continue;\n }\n\n if (deviceSocket && socketName === `@${deviceSocket}` || !deviceSocket) {\n webviews.push({\n proc: socketName,\n webview: socketNameMatch[1]\n ? `${WEBVIEW_BASE}${socketNameMatch[1]}`\n : `${WEBVIEW_BASE}${crosswalkMatch[1]}`,\n });\n }\n }\n return webviews;\n}\n\n/**\n * Allocates a local port for devtools communication\n *\n * @param {ADB} adb ADB instance\n * @param {string} socketName The remote Unix socket name\n * @param {?number} webviewDevtoolsPort The local port number or null to apply\n * autodetection\n * @returns {number} The local port number if the remote socket has been forwarded\n * successfully or `null` otherwise\n * @throws {Error} If there was an error while allocating the local port\n */\nasync function allocateDevtoolsPort (adb, socketName, webviewDevtoolsPort = null) {\n // socket names come with '@', but this should not be a part of the abstract\n // remote port, so remove it\n const remotePort = socketName.replace(/^@/, '');\n let [startPort, endPort] = DEVTOOLS_PORTS_RANGE;\n if (webviewDevtoolsPort) {\n endPort = webviewDevtoolsPort + (endPort - startPort);\n startPort = webviewDevtoolsPort;\n }\n logger.debug(`Forwarding remote port ${remotePort} to a local ` +\n `port in range ${startPort}..${endPort}`);\n if (!webviewDevtoolsPort) {\n logger.debug(`You could use the 'webviewDevtoolsPort' capability to customize ` +\n `the starting port number`);\n }\n return await DEVTOOLS_PORT_ALLOCATION_GUARD(async () => {\n let localPort;\n try {\n localPort = await findAPortNotInUse(startPort, endPort);\n } catch (e) {\n throw new Error(`Cannot find any free port to forward the Devtools socket ` +\n `in range ${startPort}..${endPort}. You could set the starting port number ` +\n `manually by providing the 'webviewDevtoolsPort' capability`);\n }\n await adb.adbExec(['forward', `tcp:${localPort}`, `localabstract:${remotePort}`]);\n return localPort;\n });\n}\n\n/**\n * @typedef {Object} WebviewProps\n * @property {string} proc The name of the Devtools Unix socket\n * @property {string} webview The web view alias. Looks like `WEBVIEW_`\n * prefix plus PID or package name\n * @property {?Object} info Webview information as it is retrieved by\n * /json/version CDP endpoint\n * @property {?Array<Object>} pages Webview pages list as it is retrieved by\n * /json/list CDP endpoint\n */\n\n/**\n * @typedef {Object} DetailCollectionOptions\n * @property {?string|number} webviewDevtoolsPort The starting port to use for webview page\n * presence check (if not the default of 9222).\n * @property {?boolean} ensureWebviewsHavePages Whether to check for webview\n * pages presence\n * @property {boolean} enableWebviewDetailsCollection Whether to collect\n * web view details and send them to Chromedriver constructor, so it could\n * select a binary more precisely based on this info.\n */\n\n/**\n * This is a wrapper for Chrome Debugger Protocol data collection.\n * No error is thrown if CDP request fails - in such case no data will be\n * recorded into the corresponding `webviewsMapping` item.\n *\n * @param {ADB} adb The ADB instance\n * @param {Array<WebviewProps>} webviewsMapping The current webviews mapping\n * !!! Each item of this array gets mutated (`info`/`pages` properties get added\n * based on the provided `opts`) if the requested details have been\n * successfully retrieved for it !!!\n * @param {DetailCollectionOptions} opts If both `ensureWebviewsHavePages` and\n * `enableWebviewDetailsCollection` properties are falsy then no details collection\n * is performed\n */\nasync function collectWebviewsDetails (adb, webviewsMapping, opts = {}) {\n if (_.isEmpty(webviewsMapping)) {\n return;\n }\n\n const {\n webviewDevtoolsPort = null,\n ensureWebviewsHavePages = null,\n enableWebviewDetailsCollection = null,\n } = opts;\n\n if (!ensureWebviewsHavePages) {\n logger.info(`Not checking whether webviews have active pages; use the ` +\n `'ensureWebviewsHavePages' cap to turn this check on`);\n }\n\n if (!enableWebviewDetailsCollection) {\n logger.info(`Not collecting web view details. Details collection might help ` +\n `to make Chromedriver initialization more precise. Use the 'enableWebviewDetailsCollection' ` +\n `cap to turn it on`);\n }\n\n if (!ensureWebviewsHavePages && !enableWebviewDetailsCollection) {\n return;\n }\n\n // Connect to each devtools socket and retrieve web view details\n logger.debug(`Collecting CDP data of ${util.pluralize('webview', webviewsMapping.length, true)}`);\n const detailCollectors = [];\n for (const item of webviewsMapping) {\n detailCollectors.push((async () => {\n let localPort;\n try {\n localPort = await allocateDevtoolsPort(adb, item.proc, webviewDevtoolsPort);\n if (enableWebviewDetailsCollection) {\n item.info = await cdpInfo(localPort);\n }\n if (ensureWebviewsHavePages) {\n item.pages = await cdpList(localPort);\n }\n } catch (e) {\n logger.debug(e);\n } finally {\n if (localPort) {\n try {\n await adb.removePortForward(localPort);\n } catch (e) {\n logger.debug(e);\n }\n }\n }\n })());\n }\n await B.all(detailCollectors);\n logger.debug(`CDP data collection completed`);\n}\n\n// https://chromedevtools.github.io/devtools-protocol/\nasync function cdpList (localPort) {\n return (await axios({\n url: `http://127.0.0.1:${localPort}/json/list`,\n timeout: CDP_REQ_TIMEOUT,\n })).data;\n}\n\n// https://chromedevtools.github.io/devtools-protocol/\nasync function cdpInfo (localPort) {\n return (await axios({\n url: `http://127.0.0.1:${localPort}/json/version`,\n timeout: CDP_REQ_TIMEOUT,\n })).data;\n}\n\n/**\n * Take a webview name like WEBVIEW_4296 and use 'adb shell ps' to figure out\n * which app package is associated with that webview. One of the reasons we\n * want to do this is to make sure we're listing webviews for the actual AUT,\n * not some other running app\n *\n * @param {object} adb - an ADB instance\n * @param {string} webview - a webview process name\n *\n * @returns {string} - the package name of the app running the webview\n * @throws {Error} If there was a failure while retrieving the process name\n */\nhelpers.procFromWebview = async function procFromWebview (adb, webview) {\n const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);\n if (!pidMatch) {\n throw new Error(`Could not find PID for webview '${webview}'`);\n }\n\n const pid = pidMatch[1];\n logger.debug(`${webview} mapped to pid ${pid}`);\n logger.debug(`Getting process name for webview '${webview}'`);\n const pkg = await adb.getNameByPid(pid);\n logger.debug(`Got process name: '${pkg}'`);\n return pkg;\n};\n\n/**\n * Parse webview names for getContexts\n *\n * @param {Array<WebviewsMapping>} webviewsMapping See note on getWebViewsMapping\n * @param {GetWebviewsOpts} opts See note on getWebViewsMapping\n * @return {Array.<string>} - a list of webview names\n */\nhelpers.parseWebviewNames = function parseWebviewNames (webviewsMapping, {\n ensureWebviewsHavePages = true,\n isChromeSession = false\n} = {}) {\n if (isChromeSession) {\n return [CHROMIUM_WIN];\n }\n\n const result = [];\n for (const {webview, pages, proc, webviewName} of webviewsMapping) {\n if (ensureWebviewsHavePages && pages?.length === 0) {\n logger.info(`Skipping the webview '${webview}' at '${proc}' ` +\n `since it has reported having zero pages`);\n continue;\n }\n if (webviewName) {\n result.push(webviewName);\n }\n }\n logger.debug(`Found ${util.pluralize('webview', result.length, true)}: ${JSON.stringify(result)}`);\n return result;\n};\n\n/**\n * @typedef {Object} GetWebviewsOpts\n * @property {string} androidDeviceSocket [null] - device socket name\n * @property {boolean} ensureWebviewsHavePages [true] - whether to check for webview\n * page presence\n * @property {number} webviewDevtoolsPort [9222] - port to use for webview page\n * presence check.\n * @property {boolean} enableWebviewDetailsCollection [true] - whether to collect\n * web view details and send them to Chromedriver constructor, so it could\n * select a binary more precisely based on this info.\n */\n\n/**\n * @typedef {Object} WebviewsMapping\n * @property {string} proc See note on WebviewProps\n * @property {string} webview See note on WebviewProps\n * @property {?Object} info See note on WebviewProps\n * @property {?Array<Object>} pages See note on WebviewProps\n * @propery {?string} webviewName An actual webview name for switching context\n */\n\n/**\n * Get a list of available webviews mapping by introspecting processes with adb,\n * where webviews are listed. It's possible to pass in a 'deviceSocket' arg, which\n * limits the webview possibilities to the one running on the Chromium devtools\n * socket we're interested in (see note on webviewsFromProcs). We can also\n * direct this method to verify whether a particular webview process actually\n * has any pages (if a process exists but no pages are found, Chromedriver will\n * not actually be able to connect to it, so this serves as a guard for that\n * strange failure mode). The strategy for checking whether any pages are\n * active involves sending a request to the remote debug server on the device,\n * hence it is also possible to specify the port on the host machine which\n * should be used for this communication.\n *\n * @param {object} adb - an ADB instance\n * @param {GetWebviewsOpts} opts\n *\n * @return {Array<WebviewsMapping>} webviewsMapping\n */\nhelpers.getWebViewsMapping = async function getWebViewsMapping (adb, {\n androidDeviceSocket = null,\n ensureWebviewsHavePages = true,\n webviewDevtoolsPort = null,\n enableWebviewDetailsCollection = true\n} = {}) {\n logger.debug('Getting a list of available webviews');\n const webviewsMapping = await webviewsFromProcs(adb, androidDeviceSocket);\n\n await collectWebviewsDetails(adb, webviewsMapping, {\n ensureWebviewsHavePages,\n enableWebviewDetailsCollection,\n webviewDevtoolsPort,\n });\n\n for (const webviewMapping of webviewsMapping) {\n const {webview, info} = webviewMapping;\n webviewMapping.webviewName = null;\n\n let wvName = webview;\n let process = undefined;\n if (!androidDeviceSocket) {\n const pkgMatch = WEBVIEW_PKG_PATTERN.exec(webview);\n try {\n // web view name could either be suffixed with PID or the package name\n // package names could not start with a digit\n const pkg = pkgMatch ? pkgMatch[1] : await helpers.procFromWebview(adb, webview);\n wvName = `${WEBVIEW_BASE}${pkg}`;\n const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);\n process = {\n name: pkg,\n id: pidMatch ? pidMatch[1] : null,\n };\n } catch (e) {\n logger.warn(e.message);\n continue;\n }\n }\n\n webviewMapping.webviewName = wvName;\n const key = toDetailsCacheKey(adb, wvName);\n if (info || process) {\n WEBVIEWS_DETAILS_CACHE.set(key, { info, process });\n } else if (WEBVIEWS_DETAILS_CACHE.has(key)) {\n WEBVIEWS_DETAILS_CACHE.delete(key);\n }\n }\n return webviewsMapping;\n};\n\n/**\n * @typedef {Object} ProcessInfo\n * @property {string} name The process name\n * @property {?string} id The process id (if could be retrieved)\n */\n\n/**\n * @typedef {Object} WebViewDetails\n * @property {?ProcessInfo} process - Web view process details\n * @property {Object} info - Web view details as returned by /json/version CDP endpoint, for example:\n * {\n * \"Browser\": \"Chrome/72.0.3601.0\",\n * \"Protocol-Version\": \"1.3\",\n * \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3601.0 Safari/537.36\",\n * \"V8-Version\": \"7.2.233\",\n * \"WebKit-Version\": \"537.36 (@cfede9db1d154de0468cb0538479f34c0755a0f4)\",\n * \"webSocketDebuggerUrl\": \"ws://localhost:9222/devtools/browser/b0b8a4fb-bb17-4359-9533-a8d9f3908bd8\"\n * }\n */\n\n/**\n * Retrieves web view details previously cached by `getWebviews` call\n *\n * @param {ADB} adb ADB instance\n * @param {string} webview The name of the web view\n * @returns {?WebViewDetails} Either `undefined` or the recent web view details\n */\nhelpers.getWebviewDetails = function getWebviewDetails (adb, webview) {\n const key = toDetailsCacheKey(adb, webview);\n return WEBVIEWS_DETAILS_CACHE.get(key);\n};\n\n/**\n * Create Chrome driver capabilities based on the provided\n * Appium capabilities\n *\n * @param {Object} opts User-provided capabilities object\n * @param {string} deviceId The identifier of the Android device under test\n * @param {?WebViewDetails} webViewDetails\n * @returns {Object} The capabilities object.\n * See https://chromedriver.chromium.org/capabilities for more details.\n */\nhelpers.createChromedriverCaps = function createChromedriverCaps (opts, deviceId, webViewDetails) {\n const caps = { chromeOptions: {} };\n\n const androidPackage = opts.chromeOptions?.androidPackage\n || opts.appPackage\n || webViewDetails?.info?.['Android-Package'];\n if (androidPackage) {\n // chromedriver raises an invalid argument error when androidPackage is 'null'\n caps.chromeOptions.androidPackage = androidPackage;\n }\n if (_.isBoolean(opts.chromeUseRunningApp)) {\n caps.chromeOptions.androidUseRunningApp = opts.chromeUseRunningApp;\n }\n if (opts.chromeAndroidPackage) {\n caps.chromeOptions.androidPackage = opts.chromeAndroidPackage;\n }\n if (opts.chromeAndroidActivity) {\n caps.chromeOptions.androidActivity = opts.chromeAndroidActivity;\n }\n if (opts.chromeAndroidProcess) {\n caps.chromeOptions.androidProcess = opts.chromeAndroidProcess;\n } else if (webViewDetails?.process?.name && webViewDetails?.process?.id) {\n caps.chromeOptions.androidProcess = webViewDetails.process.name;\n }\n if (_.toLower(opts.browserName) === 'chromium-webview') {\n caps.chromeOptions.androidActivity = opts.appActivity;\n }\n if (opts.pageLoadStrategy) {\n caps.pageLoadStrategy = opts.pageLoadStrategy;\n }\n const isChrome = _.toLower(caps.chromeOptions.androidPackage) === 'chrome';\n if (_.includes(KNOWN_CHROME_PACKAGE_NAMES, caps.chromeOptions.androidPackage) || isChrome) {\n // if we have extracted package from context name, it could come in as bare\n // \"chrome\", and so we should make sure the details are correct, including\n // not using an activity or process id\n if (isChrome) {\n caps.chromeOptions.androidPackage = CHROME_PACKAGE_NAME;\n }\n delete caps.chromeOptions.androidActivity;\n delete caps.chromeOptions.androidProcess;\n }\n // add device id from adb\n caps.chromeOptions.androidDeviceSerial = deviceId;\n\n if (_.isPlainObject(opts.loggingPrefs) || _.isPlainObject(opts.chromeLoggingPrefs)) {\n if (opts.loggingPrefs) {\n logger.warn(`The 'loggingPrefs' cap is deprecated; use the 'chromeLoggingPrefs' cap instead`);\n }\n caps.loggingPrefs = opts.chromeLoggingPrefs || opts.loggingPrefs;\n }\n if (opts.enablePerformanceLogging) {\n logger.warn(`The 'enablePerformanceLogging' cap is deprecated; simply use ` +\n `the 'chromeLoggingPrefs' cap instead, with a 'performance' key set to 'ALL'`);\n const newPref = {performance: 'ALL'};\n // don't overwrite other logging prefs that have been sent in if they exist\n caps.loggingPrefs = caps.loggingPrefs\n ? Object.assign({}, caps.loggingPrefs, newPref)\n : newPref;\n }\n\n if (opts.chromeOptions?.Arguments) {\n // merge `Arguments` and `args`\n opts.chromeOptions.args = [...(opts.chromeOptions.args || []), ...opts.chromeOptions.Arguments];\n delete opts.chromeOptions.Arguments;\n }\n\n logger.debug('Precalculated Chromedriver capabilities: ' +\n JSON.stringify(caps.chromeOptions, null, 2));\n\n const protectedCapNames = [];\n for (const [opt, val] of _.toPairs(opts.chromeOptions)) {\n if (_.isUndefined(caps.chromeOptions[opt])) {\n caps.chromeOptions[opt] = val;\n } else {\n protectedCapNames.push(opt);\n }\n }\n if (!_.isEmpty(protectedCapNames)) {\n logger.info('The following Chromedriver capabilities cannot be overridden ' +\n 'by the provided chromeOptions:');\n for (const optName of protectedCapNames) {\n logger.info(` ${optName} (${JSON.stringify(opts.chromeOptions[optName])})`);\n }\n }\n\n return caps;\n};\n\nexport default helpers;\nexport { helpers, NATIVE_WIN, WEBVIEW_WIN, WEBVIEW_BASE, CHROMIUM_WIN, KNOWN_CHROME_PACKAGE_NAMES };\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,KAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,GAAA,GAAAT,sBAAA,CAAAC,OAAA;AAEA,MAAMS,UAAU,GAAG,YAAY;AAACC,OAAA,CAAAD,UAAA,GAAAA,UAAA;AAChC,MAAME,WAAW,GAAG,SAAS;AAACD,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAC9B,MAAMC,YAAY,GAAG,UAAU;AAACF,OAAA,CAAAE,YAAA,GAAAA,YAAA;AAChC,MAAMC,YAAY,GAAI,GAAEF,WAAY,GAAE;AAACD,OAAA,CAAAG,YAAA,GAAAA,YAAA;AACvC,MAAMC,mBAAmB,GAAG,IAAIC,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Q,KAAI9G,IAAI,CAACC,SAAS,CAAC0B,IAAI,CAACkD,aAAa,CAACiC,OAAO,CAAC,CAAE,GAAE,CAAC;IAC9E;EACF;EAEA,OAAOlC,IAAI;AACb,CAAC;AAAC,IAAAmC,QAAA,GAEatI,OAAO;AAAA3B,OAAA,CAAAkK,OAAA,GAAAD,QAAA"}
|
package/lib/commands/actions.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import B from 'bluebird';
|
|
5
5
|
import jimp from 'jimp';
|
|
6
6
|
import { exec } from 'teen_process';
|
|
7
|
+
import { requireArgs } from '../utils';
|
|
7
8
|
|
|
8
9
|
const swipeStepsPerSec = 28;
|
|
9
10
|
const dragStepsPerSec = 40;
|
|
@@ -152,6 +153,26 @@ commands.fingerprint = async function fingerprint (fingerprintId) {
|
|
|
152
153
|
await this.adb.fingerprint(fingerprintId);
|
|
153
154
|
};
|
|
154
155
|
|
|
156
|
+
/**
|
|
157
|
+
* @typedef {Object} FingerprintOpts
|
|
158
|
+
* @param {string|number} fingerprintId The value is the finger_id for the finger that
|
|
159
|
+
* was "scanned". It is a unique integer that you assign for each virtual fingerprint.
|
|
160
|
+
* When the app is running you can run this same command each time the
|
|
161
|
+
* emulator prompts you for a fingerprint, you can run the adb command and pass it
|
|
162
|
+
* the finger_id to simulate the fingerprint scan.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Emulate fingerprint on Android Emulator.
|
|
167
|
+
* Only works on API 23+
|
|
168
|
+
*
|
|
169
|
+
* @param {FingerprintOpts} opts
|
|
170
|
+
*/
|
|
171
|
+
commands.mobileFingerprint = async function mobileFingerprint(opts = {}) {
|
|
172
|
+
const {fingerprintId} = requireArgs('fingerprintId', opts);
|
|
173
|
+
await this.fingerprint(fingerprintId);
|
|
174
|
+
};
|
|
175
|
+
|
|
155
176
|
commands.sendSMS = async function sendSMS (phoneNumber, message) {
|
|
156
177
|
if (!this.isEmulator()) {
|
|
157
178
|
this.log.errorAndThrow('sendSMS method is only available for emulators');
|
|
@@ -159,6 +180,23 @@ commands.sendSMS = async function sendSMS (phoneNumber, message) {
|
|
|
159
180
|
await this.adb.sendSMS(phoneNumber, message);
|
|
160
181
|
};
|
|
161
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @typedef {Object} SendSmsOptions
|
|
185
|
+
* @property {string} phoneNumber The phone number to send SMS to
|
|
186
|
+
* @property {string} message The message payload
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Emulate sending an SMS to the given phone number.
|
|
191
|
+
* Only works on emulators.
|
|
192
|
+
*
|
|
193
|
+
* @param {SendSmsOptions} opts
|
|
194
|
+
*/
|
|
195
|
+
commands.mobileSendSms = async function mobileSendSms(opts = {}) {
|
|
196
|
+
const {phoneNumber, message} = requireArgs(['phoneNumber', 'message'], opts);
|
|
197
|
+
await this.sendSMS(phoneNumber, message);
|
|
198
|
+
};
|
|
199
|
+
|
|
162
200
|
commands.gsmCall = async function gsmCall (phoneNumber, action) {
|
|
163
201
|
if (!this.isEmulator()) {
|
|
164
202
|
this.log.errorAndThrow('gsmCall method is only available for emulators');
|
|
@@ -166,6 +204,23 @@ commands.gsmCall = async function gsmCall (phoneNumber, action) {
|
|
|
166
204
|
await this.adb.gsmCall(phoneNumber, action);
|
|
167
205
|
};
|
|
168
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @typedef {Object} GsmCallOptions
|
|
209
|
+
* @property {string} phoneNumber The phone number to call to
|
|
210
|
+
* @property {call|accept|cancel|hold} action One of possible actions to take
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Emulate a GSM call to the given phone number.
|
|
215
|
+
* Only works on emulators.
|
|
216
|
+
*
|
|
217
|
+
* @param {GsmCallOptions} opts
|
|
218
|
+
*/
|
|
219
|
+
commands.mobileGsmCall = async function mobileGsmCall(opts = {}) {
|
|
220
|
+
const {phoneNumber, action} = requireArgs(['phoneNumber', 'action'], opts);
|
|
221
|
+
await this.gsmCall(phoneNumber, action);
|
|
222
|
+
};
|
|
223
|
+
|
|
169
224
|
commands.gsmSignal = async function gsmSignal (signalStrengh) {
|
|
170
225
|
if (!this.isEmulator()) {
|
|
171
226
|
this.log.errorAndThrow('gsmSignal method is only available for emulators');
|
|
@@ -173,6 +228,22 @@ commands.gsmSignal = async function gsmSignal (signalStrengh) {
|
|
|
173
228
|
await this.adb.gsmSignal(signalStrengh);
|
|
174
229
|
};
|
|
175
230
|
|
|
231
|
+
/**
|
|
232
|
+
* @typedef {Object} GsmSignalOptions
|
|
233
|
+
* @property {0|1|2|3|4} strength One of possible signal strength values, where 4 is the best signal.
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Emulate GSM signal strength change event.
|
|
238
|
+
* Only works on emulators.
|
|
239
|
+
*
|
|
240
|
+
* @param {GsmSignalOptions} opts
|
|
241
|
+
*/
|
|
242
|
+
commands.mobileGsmSignal = async function mobileGsmSignal(opts = {}) {
|
|
243
|
+
const {strength} = requireArgs('strength', opts);
|
|
244
|
+
await this.gsmSignal(strength);
|
|
245
|
+
};
|
|
246
|
+
|
|
176
247
|
commands.gsmVoice = async function gsmVoice (state) {
|
|
177
248
|
if (!this.isEmulator()) {
|
|
178
249
|
this.log.errorAndThrow('gsmVoice method is only available for emulators');
|
|
@@ -180,6 +251,22 @@ commands.gsmVoice = async function gsmVoice (state) {
|
|
|
180
251
|
await this.adb.gsmVoice(state);
|
|
181
252
|
};
|
|
182
253
|
|
|
254
|
+
/**
|
|
255
|
+
* @typedef {Object} GsmVoiceOptions
|
|
256
|
+
* @property {on|off} state
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Emulate GSM voice state change event.
|
|
261
|
+
* Only works on emulators.
|
|
262
|
+
*
|
|
263
|
+
* @param {GsmVoiceOptions} opts
|
|
264
|
+
*/
|
|
265
|
+
commands.mobileGsmVoice = async function mobileGsmVoice(opts = {}) {
|
|
266
|
+
const {state} = requireArgs('state', opts);
|
|
267
|
+
await this.gsmVoice(state);
|
|
268
|
+
};
|
|
269
|
+
|
|
183
270
|
commands.powerAC = async function powerAC (state) {
|
|
184
271
|
if (!this.isEmulator()) {
|
|
185
272
|
this.log.errorAndThrow('powerAC method is only available for emulators');
|
|
@@ -187,6 +274,22 @@ commands.powerAC = async function powerAC (state) {
|
|
|
187
274
|
await this.adb.powerAC(state);
|
|
188
275
|
};
|
|
189
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @typedef {Object} PowerAcOptions
|
|
279
|
+
* @property {on|off} state
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Emulate AC power state change.
|
|
284
|
+
* Only works on emulators.
|
|
285
|
+
*
|
|
286
|
+
* @param {GsmVoiceOptions} opts
|
|
287
|
+
*/
|
|
288
|
+
commands.mobilePowerAc = async function mobilePowerAc(opts = {}) {
|
|
289
|
+
const {state} = requireArgs('state', opts);
|
|
290
|
+
await this.powerAC(state);
|
|
291
|
+
};
|
|
292
|
+
|
|
190
293
|
commands.powerCapacity = async function powerCapacity (batteryPercent) {
|
|
191
294
|
if (!this.isEmulator()) {
|
|
192
295
|
this.log.errorAndThrow('powerCapacity method is only available for emulators');
|
|
@@ -194,6 +297,22 @@ commands.powerCapacity = async function powerCapacity (batteryPercent) {
|
|
|
194
297
|
await this.adb.powerCapacity(batteryPercent);
|
|
195
298
|
};
|
|
196
299
|
|
|
300
|
+
/**
|
|
301
|
+
* @typedef {Object} PowerCapacityOptions
|
|
302
|
+
* @property {number} percent - Percentage value in range [0, 100]
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Emulate power capacity change.
|
|
307
|
+
* Only works on emulators.
|
|
308
|
+
*
|
|
309
|
+
* @param {PowerCapacityOptions} opts
|
|
310
|
+
*/
|
|
311
|
+
commands.mobilePowerCapacity = async function mobilePowerCapacity(opts = {}) {
|
|
312
|
+
const {percent} = requireArgs('percent', opts);
|
|
313
|
+
await this.powerCapacity(percent);
|
|
314
|
+
};
|
|
315
|
+
|
|
197
316
|
commands.networkSpeed = async function networkSpeed (networkSpeed) {
|
|
198
317
|
if (!this.isEmulator()) {
|
|
199
318
|
this.log.errorAndThrow('networkSpeed method is only available for emulators');
|
|
@@ -201,6 +320,22 @@ commands.networkSpeed = async function networkSpeed (networkSpeed) {
|
|
|
201
320
|
await this.adb.networkSpeed(networkSpeed);
|
|
202
321
|
};
|
|
203
322
|
|
|
323
|
+
/**
|
|
324
|
+
* @typedef {Object} NetworkSpeedOptions
|
|
325
|
+
* @property {gsm|scsd|gprs|edge|umts|hsdpa|lte|evdo|full} speed
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Emulate different network connection speed modes.
|
|
330
|
+
* Only works on emulators.
|
|
331
|
+
*
|
|
332
|
+
* @param {NetworkSpeedOptions} opts
|
|
333
|
+
*/
|
|
334
|
+
commands.mobileNetworkSpeed = async function mobileNetworkSpeed(opts = {}) {
|
|
335
|
+
const {speed} = requireArgs('speed', opts);
|
|
336
|
+
await this.networkSpeed(speed);
|
|
337
|
+
};
|
|
338
|
+
|
|
204
339
|
/**
|
|
205
340
|
* Emulate sensors values on the connected emulator.
|
|
206
341
|
*
|
package/lib/commands/network.js
CHANGED
|
@@ -276,99 +276,27 @@ commands.getGeoLocation = async function getGeoLocation () {
|
|
|
276
276
|
altitude: parseFloat(altitude) || GEO_EPSILON,
|
|
277
277
|
};
|
|
278
278
|
};
|
|
279
|
-
// https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DPAD_CENTER
|
|
280
|
-
// in the android docs, this is how the keycodes are defined
|
|
281
|
-
const KeyCode = {
|
|
282
|
-
UP: 19,
|
|
283
|
-
DOWN: 20,
|
|
284
|
-
RIGHT: 22,
|
|
285
|
-
CENTER: 23
|
|
286
|
-
};
|
|
287
|
-
commands.toggleLocationServices = async function toggleLocationServices () {
|
|
288
|
-
this.log.info('Toggling location services');
|
|
289
|
-
let api = await this.adb.getApiLevel();
|
|
290
|
-
if (this.isEmulator()) {
|
|
291
|
-
let providers = await this.adb.getLocationProviders();
|
|
292
|
-
let isGpsEnabled = providers.indexOf('gps') !== -1;
|
|
293
|
-
await this.adb.toggleGPSLocationProvider(!isGpsEnabled);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (api > 15) {
|
|
298
|
-
let seq = [KeyCode.UP, KeyCode.UP];
|
|
299
|
-
if (api === 16) {
|
|
300
|
-
// This version of Android has a "parent" button in its action bar
|
|
301
|
-
seq.push(KeyCode.DOWN);
|
|
302
|
-
} else if (api < 28) {
|
|
303
|
-
// Newer versions of Android have the toggle in the Action bar
|
|
304
|
-
seq = [KeyCode.RIGHT, KeyCode.RIGHT, KeyCode.UP];
|
|
305
|
-
/*
|
|
306
|
-
* Once the Location services switch is OFF, it won't receive focus
|
|
307
|
-
* when going back to the Location Services settings screen unless we
|
|
308
|
-
* send a dummy keyevent (UP) *before* opening the settings screen
|
|
309
|
-
*/
|
|
310
|
-
await this.adb.keyevent(KeyCode.UP);
|
|
311
|
-
} else if (api >= 28) {
|
|
312
|
-
// Even newer versions of android have the toggle in a bar below the action bar
|
|
313
|
-
// this means a single right click will cause it to be selected.
|
|
314
|
-
seq = [KeyCode.RIGHT];
|
|
315
|
-
await this.adb.keyevent(KeyCode.UP);
|
|
316
|
-
}
|
|
317
|
-
await this.toggleSetting('LOCATION_SOURCE_SETTINGS', seq);
|
|
318
|
-
} else {
|
|
319
|
-
// There's no global location services toggle on older Android versions
|
|
320
|
-
throw new errors.NotYetImplementedError();
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
helpers.toggleSetting = async function toggleSetting (setting, preKeySeq) {
|
|
325
|
-
/*
|
|
326
|
-
* preKeySeq is the keyevent sequence to send over ADB in order
|
|
327
|
-
* to position the cursor on the right option.
|
|
328
|
-
* By default it's [up, up, down] because we usually target the 1st item in
|
|
329
|
-
* the screen, and sometimes when opening settings activities the cursor is
|
|
330
|
-
* already positionned on the 1st item, but we can't know for sure
|
|
331
|
-
*/
|
|
332
|
-
if (_.isNull(preKeySeq)) {
|
|
333
|
-
preKeySeq = [KeyCode.UP, KeyCode.UP, KeyCode.DOWN];
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
await this.openSettingsActivity(setting);
|
|
337
|
-
|
|
338
|
-
for (let key of preKeySeq) {
|
|
339
|
-
await this.doKey(key);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
let {appPackage, appActivity} = await this.adb.getFocusedPackageAndActivity();
|
|
343
279
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
/*
|
|
353
|
-
* In one particular case (enable Location Services), a pop-up is
|
|
354
|
-
* displayed on some platforms so the user accepts or refuses that Google
|
|
355
|
-
* collects location data. So we wait for that pop-up to open, if it
|
|
356
|
-
* doesn't then proceed
|
|
357
|
-
*/
|
|
358
|
-
try {
|
|
359
|
-
await this.adb.waitForNotActivity(appPackage, appActivity, 5000);
|
|
360
|
-
await this.doKey(KeyCode.RIGHT);
|
|
361
|
-
await this.doKey(KeyCode.CENTER);
|
|
362
|
-
await this.adb.waitForNotActivity(appPackage, appActivity, 5000);
|
|
363
|
-
} catch (ign) {}
|
|
364
|
-
|
|
365
|
-
await this.adb.back();
|
|
280
|
+
/**
|
|
281
|
+
* Checks if GPS is enabled
|
|
282
|
+
*
|
|
283
|
+
* @returns {Promise<Boolean>} True if yes
|
|
284
|
+
*/
|
|
285
|
+
commands.isLocationServicesEnabled = async function iLocationServicesEnabled () {
|
|
286
|
+
return (await this.adb.getLocationProviders()).includes('gps');
|
|
366
287
|
};
|
|
367
288
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Toggles GPS state
|
|
291
|
+
*/
|
|
292
|
+
commands.toggleLocationServices = async function toggleLocationServices () {
|
|
293
|
+
this.log.info('Toggling location services');
|
|
294
|
+
const isGpsEnabled = await this.isLocationServicesEnabled();
|
|
295
|
+
this.log.debug(
|
|
296
|
+
`Current GPS state: ${isGpsEnabled}. ` +
|
|
297
|
+
`The service is going to be ${isGpsEnabled ? 'disabled' : 'enabled'}`
|
|
298
|
+
);
|
|
299
|
+
await this.adb.toggleGPSLocationProvider(!isGpsEnabled);
|
|
372
300
|
};
|
|
373
301
|
|
|
374
302
|
helpers.wrapBootstrapDisconnect = async function wrapBootstrapDisconnect (wrapped) {
|
package/lib/utils.js
CHANGED
|
@@ -6,9 +6,10 @@ export const ADB_SHELL_FEATURE = 'adb_shell';
|
|
|
6
6
|
/**
|
|
7
7
|
* Assert the presence of particular keys in the given object
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
* @param {
|
|
11
|
-
* @
|
|
9
|
+
* @template {Object} T
|
|
10
|
+
* @param {string|string[]} argNames one or more key names
|
|
11
|
+
* @param {T} opts the object to check
|
|
12
|
+
* @returns {T} the same given object
|
|
12
13
|
*/
|
|
13
14
|
export function requireArgs (argNames, opts = {}) {
|
|
14
15
|
for (const argName of (_.isArray(argNames) ? argNames : [argNames])) {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"mobile",
|
|
10
10
|
"mobile testing"
|
|
11
11
|
],
|
|
12
|
-
"version": "5.
|
|
12
|
+
"version": "5.11.1",
|
|
13
13
|
"author": "Appium Contributors",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime": "^7.0.0",
|
|
51
|
-
"appium-adb": "^9.11.
|
|
51
|
+
"appium-adb": "^9.11.2",
|
|
52
52
|
"appium-chromedriver": "^5.2.0",
|
|
53
53
|
"asyncbox": "^2.8.0",
|
|
54
54
|
"axios": "^1.x",
|