From d79b6245966baaa57f7a1f785d7f9b4ea5a7f104 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Tue, 26 Mar 2024 11:52:52 -0700 Subject: [PATCH] feat: add updatedWDABundleIdSuffix to handle bundle id for updatedWDABundleId with usePreinstalledWDA (#871) * feat: do not add xctrunner automatiocally with usePreinstalledWDA * add tests * revert bad commit * tweak if condition * update lint * define updatedWDABundleIdSuffix instead * simplify --- lib/constants.js | 5 ++-- lib/webdriveragent.js | 13 +++++++--- test/unit/webdriveragent-specs.js | 42 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 82f005d1c..fd6ed4803 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,7 +1,8 @@ import path from 'path'; +const DEFAULT_TEST_BUNDLE_SUFFIX = '.xctrunner'; const WDA_RUNNER_BUNDLE_ID = 'com.facebook.WebDriverAgentRunner'; -const WDA_RUNNER_BUNDLE_ID_FOR_XCTEST = `${WDA_RUNNER_BUNDLE_ID}.xctrunner`; +const WDA_RUNNER_BUNDLE_ID_FOR_XCTEST = `${WDA_RUNNER_BUNDLE_ID}${DEFAULT_TEST_BUNDLE_SUFFIX}`; const WDA_RUNNER_APP = 'WebDriverAgentRunner-Runner.app'; const WDA_SCHEME = 'WebDriverAgentRunner'; const PROJECT_FILE = 'project.pbxproj'; @@ -19,5 +20,5 @@ export { WDA_RUNNER_BUNDLE_ID, WDA_RUNNER_APP, PROJECT_FILE, WDA_SCHEME, PLATFORM_NAME_TVOS, PLATFORM_NAME_IOS, SDK_SIMULATOR, SDK_DEVICE, WDA_BASE_URL, WDA_UPGRADE_TIMESTAMP_PATH, - WDA_RUNNER_BUNDLE_ID_FOR_XCTEST + WDA_RUNNER_BUNDLE_ID_FOR_XCTEST, DEFAULT_TEST_BUNDLE_SUFFIX }; diff --git a/lib/webdriveragent.js b/lib/webdriveragent.js index 113269228..885291e76 100644 --- a/lib/webdriveragent.js +++ b/lib/webdriveragent.js @@ -15,8 +15,8 @@ import AsyncLock from 'async-lock'; import { exec } from 'teen_process'; import { bundleWDASim } from './check-dependencies'; import { - WDA_RUNNER_BUNDLE_ID, WDA_RUNNER_BUNDLE_ID_FOR_XCTEST, WDA_RUNNER_APP, - WDA_BASE_URL, WDA_UPGRADE_TIMESTAMP_PATH + WDA_RUNNER_BUNDLE_ID, WDA_RUNNER_APP, + WDA_BASE_URL, WDA_UPGRADE_TIMESTAMP_PATH, DEFAULT_TEST_BUNDLE_SUFFIX } from './constants'; import {Xctest} from 'appium-ios-device'; import {strongbox} from '@appium/strongbox'; @@ -70,6 +70,7 @@ class WebDriverAgent { this.wdaLaunchTimeout = args.wdaLaunchTimeout || WDA_LAUNCH_TIMEOUT; this.usePreinstalledWDA = args.usePreinstalledWDA; this.xctestApiClient = null; + this.updatedWDABundleIdSuffix = args.updatedWDABundleIdSuffix ?? DEFAULT_TEST_BUNDLE_SUFFIX; this.xcodebuild = this.canSkipXcodebuild ? null @@ -111,11 +112,15 @@ class WebDriverAgent { } /** + * Return bundle id for WebDriverAgent to launch the WDA. + * The primary usage is with 'this.usePreinstalledWDA'. + * It adds `.xctrunner` as suffix by default but 'this.updatedWDABundleIdSuffix' + * lets skip it. * * @returns {string} Bundle ID for Xctest. */ get bundleIdForXctest () { - return this.updatedWDABundleId ? `${this.updatedWDABundleId}.xctrunner` : WDA_RUNNER_BUNDLE_ID_FOR_XCTEST; + return `${this.updatedWDABundleId ? this.updatedWDABundleId : WDA_RUNNER_BUNDLE_ID}${this.updatedWDABundleIdSuffix}`; } setWDAPaths (bootstrapPath, agentPath) { @@ -449,7 +454,7 @@ class WebDriverAgent { const {wdaBundleId, testBundleId} = await this.prepareWDA(); const env = { USE_PORT: this.wdaRemotePort, - WDA_PRODUCT_BUNDLE_IDENTIFIER: this.updatedWDABundleId, + WDA_PRODUCT_BUNDLE_IDENTIFIER: this.bundleIdForXctest, }; if (this.mjpegServerPort) { env.MJPEG_SERVER_PORT = this.mjpegServerPort; diff --git a/test/unit/webdriveragent-specs.js b/test/unit/webdriveragent-specs.js index 6eac94c5b..7887fbaef 100644 --- a/test/unit/webdriveragent-specs.js +++ b/test/unit/webdriveragent-specs.js @@ -340,3 +340,45 @@ describe('setupCaching()', function () { }); }); }); + + +describe('usePreinstalledWDA related functions', function () { + describe('bundleIdForXctest', function () { + it('should have xctrunner automatically', function () { + const args = Object.assign({}, fakeConstructorArgs); + args.updatedWDABundleId = 'io.appium.wda'; + const agent = new WebDriverAgent({}, args); + agent.bundleIdForXctest.should.equal('io.appium.wda.xctrunner'); + }); + + it('should have xctrunner automatically with default bundle id', function () { + const args = Object.assign({}, fakeConstructorArgs); + const agent = new WebDriverAgent({}, args); + agent.bundleIdForXctest.should.equal('com.facebook.WebDriverAgentRunner.xctrunner'); + }); + + it('should allow an empty string as xctrunner suffix', function () { + const args = Object.assign({}, fakeConstructorArgs); + args.updatedWDABundleId = 'io.appium.wda'; + args.updatedWDABundleIdSuffix = ''; + const agent = new WebDriverAgent({}, args); + agent.bundleIdForXctest.should.equal('io.appium.wda'); + }); + + it('should allow an empty string as xctrunner suffix with default bundle id', function () { + const args = Object.assign({}, fakeConstructorArgs); + args.updatedWDABundleIdSuffix = ''; + const agent = new WebDriverAgent({}, args); + agent.bundleIdForXctest.should.equal('com.facebook.WebDriverAgentRunner'); + }); + + it('should have an arbitrary xctrunner suffix', function () { + const args = Object.assign({}, fakeConstructorArgs); + args.updatedWDABundleId = 'io.appium.wda'; + args.updatedWDABundleIdSuffix = '.customsuffix'; + const agent = new WebDriverAgent({}, args); + agent.bundleIdForXctest.should.equal('io.appium.wda.customsuffix'); + }); + + }); +});