Skip to content

Commit 2d5d803

Browse files
committed
lib: update to incorporate the new USE_IP env var
Signed-off-by: Karl Baumgartner <178656887+karlbaumg@users.noreply.github.com>
1 parent f88b345 commit 2d5d803

4 files changed

Lines changed: 35 additions & 18 deletions

File tree

lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface WebDriverAgentArgs {
6464
wdaLocalPort?: number;
6565
wdaRemotePort?: number;
6666
wdaBaseUrl?: string;
67+
wdaBindingIP?: string;
6768
prebuildWDA?: boolean;
6869
webDriverAgentUrl?: string;
6970
wdaConnectionTimeout?: number;
@@ -116,6 +117,7 @@ export interface XcodeBuildArgs {
116117
useXctestrunFile?: boolean;
117118
launchTimeout?: number;
118119
wdaRemotePort?: number;
120+
wdaBindingIP?: string;
119121
updatedWDABundleId?: string;
120122
derivedDataPath?: string;
121123
mjpegServerPort?: number;

lib/utils.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ async function setRealDeviceSecurity (keychainPath, keychainPassword) {
166166
* @property {string} platformVersion - The platform version of OS.
167167
* @property {string} platformName - The platform name of iOS, tvOS
168168
*/
169+
170+
/**
171+
* Arguments for setting xctestrun file
172+
* @typedef {Object} XctestrunFileArgs
173+
* @property {DeviceInfo} deviceInfo - Information of the device under test
174+
* @property {string} sdkVersion - The Xcode SDK version of OS.
175+
* @property {string} bootstrapPath - The folder path containing xctestrun file.
176+
* @property {number|string} wdaRemotePort - The remote port WDA is listening on.
177+
* @property {string|undefined} wdaBindingIP - The IP address to bind to. If not given, it binds to all interfaces.
178+
*/
169179
/**
170180
* Creates xctestrun file per device & platform version.
171181
* We expects to have WebDriverAgentRunner_iphoneos${sdkVersion|platformVersion}-arm64.xctestrun for real device
@@ -174,19 +184,17 @@ async function setRealDeviceSecurity (keychainPath, keychainPassword) {
174184
* e.g. Xcode which has iOS SDK Version 12.2 on an intel Mac host machine generates WebDriverAgentRunner_iphonesimulator.2-x86_64.xctestrun
175185
* even if the cap has platform version 11.4
176186
*
177-
* @param {DeviceInfo} deviceInfo
178-
* @param {string} sdkVersion - The Xcode SDK version of OS.
179-
* @param {string} bootstrapPath - The folder path containing xctestrun file.
180-
* @param {number|string} wdaRemotePort - The remote port WDA is listening on.
187+
* @param {XctestrunFileArgs} args
181188
* @return {Promise<string>} returns xctestrunFilePath for given device
182189
* @throws if WebDriverAgentRunner_iphoneos${sdkVersion|platformVersion}-arm64.xctestrun for real device
183190
* or WebDriverAgentRunner_iphonesimulator${sdkVersion|platformVersion}-x86_64.xctestrun for simulator is not found @bootstrapPath,
184-
* then it will throw file not found exception
191+
* then it will throw a file not found exception
185192
*/
186-
async function setXctestrunFile (deviceInfo, sdkVersion, bootstrapPath, wdaRemotePort) {
193+
async function setXctestrunFile (args) {
194+
const {deviceInfo, sdkVersion, bootstrapPath, wdaRemotePort, wdaBindingIP} = args;
187195
const xctestrunFilePath = await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath);
188196
const xctestRunContent = await plist.parsePlistFile(xctestrunFilePath);
189-
const updateWDAPort = getAdditionalRunContent(deviceInfo.platformName, wdaRemotePort);
197+
const updateWDAPort = getAdditionalRunContent(deviceInfo.platformName, wdaRemotePort, wdaBindingIP);
190198
const newXctestRunContent = _.merge(xctestRunContent, updateWDAPort);
191199
await plist.updatePlistFile(xctestrunFilePath, newXctestRunContent, true);
192200

@@ -197,16 +205,17 @@ async function setXctestrunFile (deviceInfo, sdkVersion, bootstrapPath, wdaRemot
197205
* Return the WDA object which appends existing xctest runner content
198206
* @param {string} platformName - The name of the platform
199207
* @param {number|string} wdaRemotePort - The remote port number
200-
* @return {object} returns a runner object which has USE_PORT
208+
* @param {string|undefined} wdaBindingIP - The IP address to bind to. If not given, it binds to all interfaces.
209+
* @return {object} returns a runner object which has USE_PORT and optionally USE_IP
201210
*/
202-
function getAdditionalRunContent (platformName, wdaRemotePort) {
211+
function getAdditionalRunContent (platformName, wdaRemotePort, wdaBindingIP) {
203212
const runner = `WebDriverAgentRunner${isTvOS(platformName) ? '_tvOS' : ''}`;
204-
205213
return {
206214
[runner]: {
207215
EnvironmentVariables: {
208216
// USE_PORT must be 'string'
209-
USE_PORT: `${wdaRemotePort}`
217+
USE_PORT: `${wdaRemotePort}`,
218+
...(wdaBindingIP ? { USE_IP: wdaBindingIP } : {}),
210219
}
211220
}
212221
};

lib/webdriveragent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class WebDriverAgent {
6060
this.wdaRemotePort = ((this.isRealDevice ? args.wdaRemotePort : null) ?? args.wdaLocalPort)
6161
|| WDA_AGENT_PORT;
6262
this.wdaBaseUrl = args.wdaBaseUrl || WDA_BASE_URL;
63-
63+
this.wdaBindingIP = args.wdaBindingIP;
6464
this.prebuildWDA = args.prebuildWDA;
6565

6666
// this.args.webDriverAgentUrl guiarantees the capabilities acually
@@ -104,6 +104,7 @@ export class WebDriverAgent {
104104
updatedWDABundleId: this.updatedWDABundleId,
105105
launchTimeout: this.wdaLaunchTimeout,
106106
wdaRemotePort: this.wdaRemotePort,
107+
wdaBindingIP: this.wdaBindingIP,
107108
useXctestrunFile: this.useXctestrunFile,
108109
derivedDataPath: args.derivedDataPath,
109110
mjpegServerPort: this.mjpegServerPort,
@@ -390,6 +391,9 @@ export class WebDriverAgent {
390391
if (this.mjpegServerPort) {
391392
xctestEnv.MJPEG_SERVER_PORT = this.mjpegServerPort;
392393
}
394+
if (this.wdaBindingIP) {
395+
xctestEnv.USE_IP = this.wdaBindingIP;
396+
}
393397
this.log.info('Launching WebDriverAgent on the device without xcodebuild');
394398
if (this.isRealDevice) {
395399
// Current method to launch WDA process can be done via 'xcrun devicectl',

lib/xcodebuild.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class XcodeBuild {
8383
this.launchTimeout = args.launchTimeout;
8484

8585
this.wdaRemotePort = args.wdaRemotePort;
86+
this.wdaBindingIP = args.wdaBindingIP;
8687

8788
this.updatedWDABundleId = args.updatedWDABundleId;
8889
this.derivedDataPath = args.derivedDataPath;
@@ -116,12 +117,13 @@ export class XcodeBuild {
116117
platformVersion: this.platformVersion || '',
117118
platformName: this.platformName || ''
118119
};
119-
this.xctestrunFilePath = await setXctestrunFile(
120-
deviceInfo,
121-
this.iosSdkVersion || '',
122-
this.bootstrapPath,
123-
this.wdaRemotePort || 8100
124-
);
120+
this.xctestrunFilePath = await setXctestrunFile({
121+
deviceInfo,
122+
sdkVersion: this.iosSdkVersion || '',
123+
bootstrapPath: this.bootstrapPath,
124+
wdaRemotePort: this.wdaRemotePort || 8100,
125+
wdaBindingIP: this.wdaBindingIP
126+
});
125127
return;
126128
}
127129

0 commit comments

Comments
 (0)