From 2025d9880221324627cc0dca0653ec16ecd235c8 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:06:34 +0900 Subject: [PATCH 01/11] feat: add includeAllApps parameter --- lib/remote-debugger.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/remote-debugger.js b/lib/remote-debugger.js index fe2026f..6927ad4 100644 --- a/lib/remote-debugger.js +++ b/lib/remote-debugger.js @@ -119,6 +119,7 @@ class RemoteDebugger extends EventEmitter { isSafari = true, includeSafari = false, useNewSafari = false, + includeAllApps = false, pageLoadMs, host, port = REMOTE_DEBUGGER_PORT, @@ -140,6 +141,7 @@ class RemoteDebugger extends EventEmitter { this.isSafari = isSafari; this.includeSafari = includeSafari; this.useNewSafari = useNewSafari; + this.includeAllApps = includeAllApps; this.pageLoadMs = pageLoadMs; log.debug(`useNewSafari --> ${this.useNewSafari}`); From a9467891c4a38cd4e3cc2bf8fadeeeabafebd877 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:17:33 +0900 Subject: [PATCH 02/11] feat: do not filter app keys by possibleBundleIds --- lib/mixins/connect.js | 2 +- lib/utils.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mixins/connect.js b/lib/mixins/connect.js index 87d52fc..9847136 100644 --- a/lib/mixins/connect.js +++ b/lib/mixins/connect.js @@ -191,7 +191,7 @@ async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) { } logApplicationDictionary(this.appDict); - const possibleAppIds = getPossibleDebuggerAppKeys(bundleIds, this.appDict); + const possibleAppIds = getPossibleDebuggerAppKeys(this.includeAllApps, bundleIds, this.appDict); log.debug(`Trying out the possible app ids: ${possibleAppIds.join(', ')} (try #${retryCount + 1} of ${maxTries})`); for (const attemptedAppIdKey of possibleAppIds) { try { diff --git a/lib/utils.js b/lib/utils.js index 57f245b..318d0f4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -155,7 +155,10 @@ function appIdForBundle (bundleId, appDict) { return appId; } -function getPossibleDebuggerAppKeys (bundleIds, appDict) { +function getPossibleDebuggerAppKeys (includeAllApps, bundleIds, appDict) { + if (includeAllApps) { + return _.uniq(Object.keys(appDict)); + } let proxiedAppIds = []; // go through the possible bundle identifiers From cfaaa856469d1e0270e504beddcb7bee0fa4d7f4 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:25:52 +0900 Subject: [PATCH 03/11] refactor: assign types to getPossibleDebuggerAppKeys function --- lib/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 318d0f4..af5dff3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -155,6 +155,14 @@ function appIdForBundle (bundleId, appDict) { return appId; } +/** + * When includeAllApps is false, it returns appKeys filtered by bundleIds. + * Otherwise, returns all appKeys in appDict. + * @param {boolean} includeAllApps + * @param {string[]} bundleIds + * @param {Record} appDict + * @returns {string[]} + */ function getPossibleDebuggerAppKeys (includeAllApps, bundleIds, appDict) { if (includeAllApps) { return _.uniq(Object.keys(appDict)); From 7f1ca1dae30bfc3fedc38a390d6d6d527b17b1b6 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:32:14 +0900 Subject: [PATCH 04/11] refactor: assign types to appIdForBundle and getDebuggerAppKey function --- lib/utils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index af5dff3..ddc1ab0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -105,9 +105,12 @@ function pageArrayFromDict (pageDict) { return newPageArray; } -/* +/** * Given a bundle id, finds the correct remote debugger app that is * connected. + * @param {string} bundleId + * @param {Record} appDict + * @returns {string|undefined} */ function getDebuggerAppKey (bundleId, appDict) { let appId; @@ -138,6 +141,12 @@ function getDebuggerAppKey (bundleId, appDict) { return appId; } +/** + * + * @param {string} bundleId + * @param {Record} appDict + * @returns {string|undefined} + */ function appIdForBundle (bundleId, appDict) { let appId; for (const [key, data] of _.toPairs(appDict)) { From 2b798e20426c367cc039f942cceb96edd1c2dd94 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:25:24 +0900 Subject: [PATCH 05/11] test: add tests for getPossibleDebuggerAppKeys function --- test/unit/utils-specs.js | 66 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index 955fb2c..0a7b41b 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -1,4 +1,6 @@ -import { pageArrayFromDict, checkParams, appInfoFromDict, getDebuggerAppKey } from '../../lib/utils'; +import { + pageArrayFromDict, checkParams, appInfoFromDict, getDebuggerAppKey, getPossibleDebuggerAppKeys +} from '../../lib/utils'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; @@ -57,6 +59,68 @@ describe('utils', function () { expect(getDebuggerAppKey('io.appium.bundle', {})).to.not.exist; }); }); + describe('getPossibleDebuggerAppKeys', function () { + describe('when includeAllApps is false', function () { + it('should return the app key of the specified bundleIds', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle1' + }, + ['43']: { + bundleId: 'io.appium.bundle2' + }, + }; + expect(getPossibleDebuggerAppKeys(false, ['io.appium.bundle1'], appDict)).to.eql(['42']); + }); + const webviewBundleIds = [ + 'com.apple.WebKit.WebContent', + 'process-com.apple.WebKit.WebContent', + 'process-SafariViewService', + 'com.apple.SafariViewService', + '*' + ]; + for (const webviewBundleId of webviewBundleIds) { + it(`should return the app key of ${webviewBundleId}`, function () { + const appDict = { + ['42']: { + bundleId: webviewBundleId + } + }; + expect(getPossibleDebuggerAppKeys(false, [], appDict)).to.eql(['42']); + }); + } + it('should return the app key for the bundleIds when proxied', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle', + isProxy: false + }, + ['43']: { + bundleId: 'io.appium.proxied.bundle', + isProxy: true, + hostId: '42' + } + }; + expect(getPossibleDebuggerAppKeys(false, ['io.appium.bundle'], appDict)).to.eql(['42', '43']); + }); + it('should return an empty array when there is no appropriate app', function () { + expect(getPossibleDebuggerAppKeys(false, 'io.appium.bundle', {})).to.eql([]); + }); + }); + describe('when includeAllApps is true', function () { + it('should return all app key from the assigned appDict', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle1' + }, + ['43']: { + bundleId: 'io.appium.bundle2' + }, + }; + expect(getPossibleDebuggerAppKeys(true, ['io.appium.bundle1'], appDict)).to.eql(['42', '43']); + }); + }); + }); describe('pageArrayFromDict', function () { let basePageDict = { 1: { From 81240cfcab75f29516599d4811dae46a82920fdf Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:35:17 +0900 Subject: [PATCH 06/11] refactor: remove includeAllApps occurrences --- lib/mixins/connect.js | 2 +- lib/remote-debugger.js | 2 - lib/utils.js | 6 +-- test/unit/utils-specs.js | 91 +++++++++++++++++----------------------- 4 files changed, 40 insertions(+), 61 deletions(-) diff --git a/lib/mixins/connect.js b/lib/mixins/connect.js index 9847136..87d52fc 100644 --- a/lib/mixins/connect.js +++ b/lib/mixins/connect.js @@ -191,7 +191,7 @@ async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) { } logApplicationDictionary(this.appDict); - const possibleAppIds = getPossibleDebuggerAppKeys(this.includeAllApps, bundleIds, this.appDict); + const possibleAppIds = getPossibleDebuggerAppKeys(bundleIds, this.appDict); log.debug(`Trying out the possible app ids: ${possibleAppIds.join(', ')} (try #${retryCount + 1} of ${maxTries})`); for (const attemptedAppIdKey of possibleAppIds) { try { diff --git a/lib/remote-debugger.js b/lib/remote-debugger.js index 6927ad4..fe2026f 100644 --- a/lib/remote-debugger.js +++ b/lib/remote-debugger.js @@ -119,7 +119,6 @@ class RemoteDebugger extends EventEmitter { isSafari = true, includeSafari = false, useNewSafari = false, - includeAllApps = false, pageLoadMs, host, port = REMOTE_DEBUGGER_PORT, @@ -141,7 +140,6 @@ class RemoteDebugger extends EventEmitter { this.isSafari = isSafari; this.includeSafari = includeSafari; this.useNewSafari = useNewSafari; - this.includeAllApps = includeAllApps; this.pageLoadMs = pageLoadMs; log.debug(`useNewSafari --> ${this.useNewSafari}`); diff --git a/lib/utils.js b/lib/utils.js index ddc1ab0..27664c3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -167,15 +167,11 @@ function appIdForBundle (bundleId, appDict) { /** * When includeAllApps is false, it returns appKeys filtered by bundleIds. * Otherwise, returns all appKeys in appDict. - * @param {boolean} includeAllApps * @param {string[]} bundleIds * @param {Record} appDict * @returns {string[]} */ -function getPossibleDebuggerAppKeys (includeAllApps, bundleIds, appDict) { - if (includeAllApps) { - return _.uniq(Object.keys(appDict)); - } +function getPossibleDebuggerAppKeys(bundleIds, appDict) { let proxiedAppIds = []; // go through the possible bundle identifiers diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index 0a7b41b..f52f4c1 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -60,65 +60,50 @@ describe('utils', function () { }); }); describe('getPossibleDebuggerAppKeys', function () { - describe('when includeAllApps is false', function () { - it('should return the app key of the specified bundleIds', function () { - const appDict = { - ['42']: { - bundleId: 'io.appium.bundle1' - }, - ['43']: { - bundleId: 'io.appium.bundle2' - }, - }; - expect(getPossibleDebuggerAppKeys(false, ['io.appium.bundle1'], appDict)).to.eql(['42']); - }); - const webviewBundleIds = [ - 'com.apple.WebKit.WebContent', - 'process-com.apple.WebKit.WebContent', - 'process-SafariViewService', - 'com.apple.SafariViewService', - '*' - ]; - for (const webviewBundleId of webviewBundleIds) { - it(`should return the app key of ${webviewBundleId}`, function () { - const appDict = { - ['42']: { - bundleId: webviewBundleId - } - }; - expect(getPossibleDebuggerAppKeys(false, [], appDict)).to.eql(['42']); - }); - } - it('should return the app key for the bundleIds when proxied', function () { + it('should return the app key of the specified bundleIds', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle1' + }, + ['43']: { + bundleId: 'io.appium.bundle2' + }, + }; + expect(getPossibleDebuggerAppKeys(['io.appium.bundle1'], appDict)).to.eql(['42']); + }); + const webviewBundleIds = [ + 'com.apple.WebKit.WebContent', + 'process-com.apple.WebKit.WebContent', + 'process-SafariViewService', + 'com.apple.SafariViewService', + '*' + ]; + for (const webviewBundleId of webviewBundleIds) { + it(`should return the app key of ${webviewBundleId}`, function () { const appDict = { ['42']: { - bundleId: 'io.appium.bundle', - isProxy: false - }, - ['43']: { - bundleId: 'io.appium.proxied.bundle', - isProxy: true, - hostId: '42' + bundleId: webviewBundleId } }; - expect(getPossibleDebuggerAppKeys(false, ['io.appium.bundle'], appDict)).to.eql(['42', '43']); - }); - it('should return an empty array when there is no appropriate app', function () { - expect(getPossibleDebuggerAppKeys(false, 'io.appium.bundle', {})).to.eql([]); + expect(getPossibleDebuggerAppKeys([], appDict)).to.eql(['42']); }); + } + it('should return the app key for the bundleIds when proxied', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle', + isProxy: false + }, + ['43']: { + bundleId: 'io.appium.proxied.bundle', + isProxy: true, + hostId: '42' + } + }; + expect(getPossibleDebuggerAppKeys(['io.appium.bundle'], appDict)).to.eql(['42', '43']); }); - describe('when includeAllApps is true', function () { - it('should return all app key from the assigned appDict', function () { - const appDict = { - ['42']: { - bundleId: 'io.appium.bundle1' - }, - ['43']: { - bundleId: 'io.appium.bundle2' - }, - }; - expect(getPossibleDebuggerAppKeys(true, ['io.appium.bundle1'], appDict)).to.eql(['42', '43']); - }); + it('should return an empty array when there is no appropriate app', function () { + expect(getPossibleDebuggerAppKeys('io.appium.bundle', {})).to.eql([]); }); }); describe('pageArrayFromDict', function () { From 907f7870e4a32a154cb628faf8beac8e2f116693 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:42:15 +0900 Subject: [PATCH 07/11] feat: add wildcard usage in additionalWebviewBundleIds capability --- lib/utils.js | 4 +++- test/unit/utils-specs.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 27664c3..8890f51 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -172,6 +172,9 @@ function appIdForBundle (bundleId, appDict) { * @returns {string[]} */ function getPossibleDebuggerAppKeys(bundleIds, appDict) { + if (bundleIds.includes(WILDCARD_BUNDLE_ID)) { + return _.uniq(Object.keys(appDict)); + } let proxiedAppIds = []; // go through the possible bundle identifiers @@ -180,7 +183,6 @@ function getPossibleDebuggerAppKeys(bundleIds, appDict) { WEB_CONTENT_PROCESS_BUNDLE_ID, SAFARI_VIEW_PROCESS_BUNDLE_ID, SAFARI_VIEW_BUNDLE_ID, - WILDCARD_BUNDLE_ID, ...bundleIds, ]); log.debug(`Checking for bundle identifiers: ${possibleBundleIds.join(', ')}`); diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index f52f4c1..1a9c726 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -75,8 +75,7 @@ describe('utils', function () { 'com.apple.WebKit.WebContent', 'process-com.apple.WebKit.WebContent', 'process-SafariViewService', - 'com.apple.SafariViewService', - '*' + 'com.apple.SafariViewService' ]; for (const webviewBundleId of webviewBundleIds) { it(`should return the app key of ${webviewBundleId}`, function () { @@ -105,6 +104,17 @@ describe('utils', function () { it('should return an empty array when there is no appropriate app', function () { expect(getPossibleDebuggerAppKeys('io.appium.bundle', {})).to.eql([]); }); + it('should return the all app keys when the bundlIds array includes a wildcard', function () { + const appDict = { + ['42']: { + bundleId: 'io.appium.bundle1' + }, + ['43']: { + bundleId: 'io.appium.bundle2' + }, + }; + expect(getPossibleDebuggerAppKeys(['*'], appDict)).to.eql(['42', '43']); + }); }); describe('pageArrayFromDict', function () { let basePageDict = { From 71af46dac14b24f69b345e38280d2ea5a0b28306 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:57:59 +0900 Subject: [PATCH 08/11] docs: update comment --- lib/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 8890f51..26120e6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -165,8 +165,8 @@ function appIdForBundle (bundleId, appDict) { } /** - * When includeAllApps is false, it returns appKeys filtered by bundleIds. - * Otherwise, returns all appKeys in appDict. + * Find app keys based on assigned bundleIds from appDict + * When bundleIds includes a wildcard ('*'), returns all appKeys in appDict. * @param {string[]} bundleIds * @param {Record} appDict * @returns {string[]} From 0111a4e9455ca7ddc1a5c1d4ba935e3402ccc909 Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:04:11 +0900 Subject: [PATCH 09/11] feat: add debug log --- lib/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.js b/lib/utils.js index 26120e6..1a5ff07 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -173,6 +173,7 @@ function appIdForBundle (bundleId, appDict) { */ function getPossibleDebuggerAppKeys(bundleIds, appDict) { if (bundleIds.includes(WILDCARD_BUNDLE_ID)) { + log.debug(`Skip checking bundle identifiers because the bundleIds includes a wildcard`); return _.uniq(Object.keys(appDict)); } let proxiedAppIds = []; From d92627f80b4bbbefd5bd45df6bff7843d9e8cb0d Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:09:32 +0900 Subject: [PATCH 10/11] fix: keep WILDCARD_BUNDLE_ID for Safari --- lib/utils.js | 1 + test/unit/utils-specs.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 1a5ff07..084a378 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -184,6 +184,7 @@ function getPossibleDebuggerAppKeys(bundleIds, appDict) { WEB_CONTENT_PROCESS_BUNDLE_ID, SAFARI_VIEW_PROCESS_BUNDLE_ID, SAFARI_VIEW_BUNDLE_ID, + WILDCARD_BUNDLE_ID, ...bundleIds, ]); log.debug(`Checking for bundle identifiers: ${possibleBundleIds.join(', ')}`); diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index 1a9c726..219cdc7 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -75,7 +75,8 @@ describe('utils', function () { 'com.apple.WebKit.WebContent', 'process-com.apple.WebKit.WebContent', 'process-SafariViewService', - 'com.apple.SafariViewService' + 'com.apple.SafariViewService', + '*', ]; for (const webviewBundleId of webviewBundleIds) { it(`should return the app key of ${webviewBundleId}`, function () { From 98663071263c3651d80c61aa43f490b429c4a4bb Mon Sep 17 00:00:00 2001 From: mwakizaka <21286384+mwakizaka@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:12:34 +0900 Subject: [PATCH 11/11] refactor: remove unnecessary backquotes --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 084a378..5380906 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -173,7 +173,7 @@ function appIdForBundle (bundleId, appDict) { */ function getPossibleDebuggerAppKeys(bundleIds, appDict) { if (bundleIds.includes(WILDCARD_BUNDLE_ID)) { - log.debug(`Skip checking bundle identifiers because the bundleIds includes a wildcard`); + log.debug('Skip checking bundle identifiers because the bundleIds includes a wildcard'); return _.uniq(Object.keys(appDict)); } let proxiedAppIds = [];