@@ -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 } ;
0 commit comments