diff --git a/lib/utils.ts b/lib/utils.ts index 1345b2035..893f0c3ea 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -4,15 +4,13 @@ import path, { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { log } from './logger'; import _ from 'lodash'; -import { WDA_RUNNER_BUNDLE_ID, PLATFORM_NAME_TVOS } from './constants'; +import { PLATFORM_NAME_TVOS } from './constants'; import B from 'bluebird'; import _fs from 'node:fs'; import { waitForCondition } from 'asyncbox'; import { arch } from 'node:os'; import type { DeviceInfo } from './types'; -const PROJECT_FILE = 'project.pbxproj'; - // Get current filename - works in both CommonJS and ESM const currentFilename = typeof __filename !== 'undefined' @@ -94,47 +92,6 @@ export function isTvOS (platformName: string): boolean { return _.toLower(platformName) === _.toLower(PLATFORM_NAME_TVOS); } -/** - * Update WebDriverAgentRunner project bundle ID with newBundleId. - * This method assumes project file is in the correct state. - * @param agentPath - Path to the .xcodeproj directory. - * @param newBundleId the new bundle ID used to update. - */ -export async function updateProjectFile (agentPath: string, newBundleId: string): Promise { - const projectFilePath = path.resolve(agentPath, PROJECT_FILE); - try { - // Assuming projectFilePath is in the correct state, create .old from projectFilePath - await fs.copyFile(projectFilePath, `${projectFilePath}.old`); - await replaceInFile(projectFilePath, new RegExp(_.escapeRegExp(WDA_RUNNER_BUNDLE_ID), 'g'), newBundleId); - log.debug(`Successfully updated '${projectFilePath}' with bundle id '${newBundleId}'`); - } catch (err: any) { - log.debug(`Error updating project file: ${err.message}`); - log.warn(`Unable to update project file '${projectFilePath}' with ` + - `bundle id '${newBundleId}'. WebDriverAgent may not start`); - } -} - -/** - * Reset WebDriverAgentRunner project bundle ID to correct state. - * @param agentPath - Path to the .xcodeproj directory. - */ -export async function resetProjectFile (agentPath: string): Promise { - const projectFilePath = path.join(agentPath, PROJECT_FILE); - try { - // restore projectFilePath from .old file - if (!await fs.exists(`${projectFilePath}.old`)) { - return; // no need to reset - } - await fs.mv(`${projectFilePath}.old`, projectFilePath); - log.debug(`Successfully reset '${projectFilePath}' with bundle id '${WDA_RUNNER_BUNDLE_ID}'`); - } catch (err: any) { - log.debug(`Error resetting project file: ${err.message}`); - log.warn(`Unable to reset project file '${projectFilePath}' with ` + - `bundle id '${WDA_RUNNER_BUNDLE_ID}'. WebDriverAgent has been ` + - `modified and not returned to the original state.`); - } -} - export async function setRealDeviceSecurity (keychainPath: string, keychainPassword: string): Promise { log.debug('Setting security for iOS device'); await exec('security', ['-v', 'list-keychains', '-s', keychainPath]); @@ -382,12 +339,4 @@ async function getPIDsUsingPattern (pattern: string): Promise { } } -async function replaceInFile (file: string, find: string | RegExp, replace: string): Promise { - const contents = await fs.readFile(file, 'utf8'); - - const newContents = contents.replace(find, replace); - if (newContents !== contents) { - await fs.writeFile(file, newContents, 'utf8'); - } -} diff --git a/lib/webdriveragent.ts b/lib/webdriveragent.ts index ba8dcf36c..e2061392a 100644 --- a/lib/webdriveragent.ts +++ b/lib/webdriveragent.ts @@ -355,7 +355,6 @@ export class WebDriverAgent { this.log.info('Shutting down sub-processes'); if (this._xcodebuild) { await this.xcodebuild.quit(); - await this.xcodebuild.reset(); } } else { this.log.debug('Do not stop xcodebuild nor XCTest session ' + diff --git a/lib/xcodebuild.ts b/lib/xcodebuild.ts index fde24528a..3d5a4600d 100644 --- a/lib/xcodebuild.ts +++ b/lib/xcodebuild.ts @@ -6,8 +6,7 @@ import { log as defaultLogger } from './logger'; import B from 'bluebird'; import { setRealDeviceSecurity, setXctestrunFile, - updateProjectFile, resetProjectFile, killProcess, - getWDAUpgradeTimestamp, isTvOS + killProcess, getWDAUpgradeTimestamp, isTvOS } from './utils'; import _ from 'lodash'; import path from 'path'; @@ -135,7 +134,7 @@ export class XcodeBuild { /** * Initializes the XcodeBuild instance with a no-session proxy. - * Sets up xctestrun file if needed, or updates project bundle ID for real devices. + * Sets up xctestrun file if needed. * @param noSessionProxy - The proxy instance for WDA communication */ async init (noSessionProxy: NoSessionProxy): Promise { @@ -157,19 +156,6 @@ export class XcodeBuild { }); return; } - - // if necessary, update the bundleId to user's specification - if (this.realDevice) { - // In case the project still has the user specific bundle ID, reset the project file first. - // - We do this reset even if updatedWDABundleId is not specified, - // since the previous updatedWDABundleId test has generated the user specific bundle ID project file. - // - We don't call resetProjectFile for simulator, - // since simulator test run will work with any user specific bundle ID. - await resetProjectFile(this.agentPath); - if (this.updatedWDABundleId) { - await updateProjectFile(this.agentPath, this.updatedWDABundleId); - } - } } /** @@ -211,17 +197,6 @@ export class XcodeBuild { return await this._derivedDataPathPromise; } - /** - * Resets the project file to its original state. - * Restores the bundle ID to the original value for real devices if it was modified. - */ - async reset (): Promise { - // if necessary, reset the bundleId to original value - if (this.realDevice && this.updatedWDABundleId) { - await resetProjectFile(this.agentPath); - } - } - /** * Pre-builds WebDriverAgent before launching tests. * Performs a build-only operation and sets usePrebuiltWDA flag. @@ -360,7 +335,7 @@ export class XcodeBuild { } args.push('-destination', `id=${this.device.udid}`); - let versionMatch; + let versionMatch: RegExpMatchArray | null = null; if (this.platformVersion && (versionMatch = new RegExp(/^(\d+)\.(\d+)/).exec(this.platformVersion))) { args.push( `${isTvOS(this.platformName || '') ? 'TV' : 'IPHONE'}OS_DEPLOYMENT_TARGET=${versionMatch[1]}.${versionMatch[2]}` @@ -383,6 +358,9 @@ export class XcodeBuild { `CODE_SIGN_IDENTITY=${this.xcodeSigningId}`, ); } + if (this.updatedWDABundleId) { + args.push(`PRODUCT_BUNDLE_IDENTIFIER=${this.updatedWDABundleId}`); + } } if (!process.env.APPIUM_XCUITEST_TREAT_WARNINGS_AS_ERRORS) {