Skip to content

Commit

Permalink
feat: add updatedWDABundleIdSuffix to handle bundle id for updatedWDA…
Browse files Browse the repository at this point in the history
…BundleId 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
  • Loading branch information
KazuCocoa authored Mar 26, 2024
1 parent e86c4b2 commit d79b624
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
};
13 changes: 9 additions & 4 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions test/unit/webdriveragent-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});
});

0 comments on commit d79b624

Please sign in to comment.