Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce a wildcard usage for additionalWebviewBundleIds to get webview contexts of other apps #346

Merged
merged 11 commits into from
Nov 17, 2023
24 changes: 22 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>} appDict
* @returns {string|undefined}
*/
function getDebuggerAppKey (bundleId, appDict) {
let appId;
Expand Down Expand Up @@ -138,6 +141,12 @@ function getDebuggerAppKey (bundleId, appDict) {
return appId;
}

/**
*
* @param {string} bundleId
* @param {Record<string, any>} appDict
* @returns {string|undefined}
*/
function appIdForBundle (bundleId, appDict) {
let appId;
for (const [key, data] of _.toPairs(appDict)) {
Expand All @@ -155,7 +164,18 @@ function appIdForBundle (bundleId, appDict) {
return appId;
}

function getPossibleDebuggerAppKeys (bundleIds, 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<string, any>} appDict
* @returns {string[]}
*/
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 = [];

// go through the possible bundle identifiers
Expand Down
62 changes: 61 additions & 1 deletion test/unit/utils-specs.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -57,6 +59,64 @@ describe('utils', function () {
expect(getDebuggerAppKey('io.appium.bundle', {})).to.not.exist;
});
});
describe('getPossibleDebuggerAppKeys', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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: webviewBundleId
}
};
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']);
});
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 = {
1: {
Expand Down