Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uninstall wda with '.xctrunner' suffix for real device #1052

Merged
merged 20 commits into from
Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
get bundleid via ios-device, revert some implementations
  • Loading branch information
KazuCocoa committed Aug 29, 2019
commit 24078cd18bf064301d28a79531e4625b26bcafe4
24 changes: 1 addition & 23 deletions lib/wda/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,8 @@ function getXctestrunFileName (deviceInfo, version) {
? `WebDriverAgentRunner_tvOS_appletv${deviceInfo.isRealDevice ? `os${version}-arm64` : `simulator${version}-x86_64`}.xctestrun`
: `WebDriverAgentRunner_iphone${deviceInfo.isRealDevice ? `os${version}-arm64` : `simulator${version}-x86_64`}.xctestrun`;
}


/**
* Return the path of Info.plist file
* @param {DeviceInfo} deviceInfo
* @param {string} bootstrapPath
* @return {string} returns Info.plist file path
*/
function getBundleIdFromInfoPlistPath (deviceInfo, bootstrapPath) {
const infoPlist = isTvOS(deviceInfo.platformName)
? `Debug-appletv${deviceInfo.isRealDevice ? 'os' : 'simulator'}/WebDriverAgentRunner_tvOS-Runner.app/Info.plist`
: `Debug-iphone${deviceInfo.isRealDevice ? 'os' : 'simulator'}/WebDriverAgentRunner-Runner.app/Info.plist`;

return path.resolve(bootstrapPath, infoPlist);
}

async function getCFBundleIdentifierFromPlist (deviceInfo, bootstrapPath) {
const parsedPlist = await plist.parsePlistFile(
getBundleIdFromInfoPlistPath(deviceInfo, bootstrapPath), false);
return parsedPlist.CFBundleIdentifier;
}

async function killProcess (name, proc) {

if (proc && proc.proc) {
log.info(`Shutting down ${name} process (pid ${proc.proc.pid})`);
try {
Expand Down Expand Up @@ -284,7 +263,6 @@ async function getWDAUpgradeTimestamp (bootstrapPath) {

export { updateProjectFile, resetProjectFile, setRealDeviceSecurity,
fixForXcode9, getAdditionalRunContent, getXctestrunFileName,
getBundleIdFromInfoPlistPath, getCFBundleIdentifierFromPlist,
generateXcodeConfigFile, setXctestrunFile, getXctestrunFilePath, killProcess,
randomInt, getWDAUpgradeTimestamp, CARTHAGE_ROOT,
};
82 changes: 37 additions & 45 deletions lib/wda/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { JWProxy } from 'appium-base-driver';
import { fs, util } from 'appium-support';
import log from '../logger';
import { NoSessionProxy } from './no-session-proxy';
import { getWDAUpgradeTimestamp, CARTHAGE_ROOT, getCFBundleIdentifierFromPlist } from './utils';
import { getWDAUpgradeTimestamp, CARTHAGE_ROOT } from './utils';
import { resetXCTestProcesses, getPIDsListeningOnPort, isLocalHost } from '../utils';
import XcodeBuild from './xcodebuild';
import iProxy from './iproxy';
import { exec } from 'teen_process';
import AsyncLock from 'async-lock';
import { BOOTSTRAP_PATH, WDA_BUNDLE_ID, WDA_RUNNER_BUNDLE_ID, checkForDependencies } from 'appium-webdriveragent';
import { services } from 'appium-ios-device';

const WDA_LAUNCH_TIMEOUT = 60 * 1000;
const WDA_AGENT_PORT = 8100;
const WDA_BASE_URL = 'http://localhost';
const WDA_XCTRUNNER_SUFFIX = '.xctrunner';
const WDA_CF_BUNDLE_NAME = 'WebDriverAgentRunner-Runner';

const SHARED_RESOURCES_GUARD = new AsyncLock();

Expand Down Expand Up @@ -158,27 +159,17 @@ class WebDriverAgent {
}

/**
* Uninstall WDA from the test device.
* If WDA is built by Xcode 10-, the bundle id is WDA_BUNDLE_ID.
* If WDA is build by Xcode 11, the bundle id is 'com.facebook.WebDriverAgentRunner.xctrunner' for simulator.
* 'com.customised.WDA.xctrunner' for real device if a user sets 'bundleId' as 'com.customised.WDA'.
*
* @param {string} bundleId The bundle id which will be uninstalled
* Uninstall WDAs from the test device.
* Over Xcode 11, multiple WDA can be in the device since Xcode 11 generates different WDA.
* Appium does not expect multiple WDAs are running on a device.
*/
async uninstall (bundleId = WDA_RUNNER_BUNDLE_ID) {
async uninstall () {
try {
// For (this.xcodeVersion && this.xcodeVersion.major < 11)
// this.xcodeVersion will be null when this.opts.webDriverAgentUrl is given.
// But webDriverAgentUrl has a value means users use their own WDA instead of this class.
// We can expect uninstall does not happen, in general.
// For Xcode 11+
// On simulator, the bundle id should be 'com.facebook.WebDriverAgentRunner.xctrunner'
// even if 'updatedWDABundleId' was given
bundleId = (this.xcodeVersion && this.xcodeVersion.major < 11)
? WDA_BUNDLE_ID
: `${this.realDevice ? bundleId : WDA_RUNNER_BUNDLE_ID}${WDA_XCTRUNNER_SUFFIX}`;
log.debug(`Removing WDA application from device: '${bundleId}'`);
await this.device.removeApp(bundleId);
const bundleIds = await this.getInstalledWDBundleId();
log.debug(`Uninstalling ${bundleIds}`);
for (const bundleId of bundleIds) {
await this.device.removeApp(bundleId);
}
} catch (e) {
log.warn(`WebDriverAgent uninstall failed. Perhaps, it is already uninstalled? Original error: ${JSON.stringify(e)}`);
}
Expand Down Expand Up @@ -383,7 +374,7 @@ class WebDriverAgent {
// for real device
if (util.hasValue(productBundleIdentifier) && util.hasValue(this.updatedWDABundleId) && this.updatedWDABundleId !== productBundleIdentifier) {
log.info(`Will uninstall running WDA since it has different bundle id. The actual value is '${productBundleIdentifier}'.`);
return await this.uninstall(productBundleIdentifier);
return await this.uninstall();
}
// for simulator
if (util.hasValue(productBundleIdentifier) && !util.hasValue(this.updatedWDABundleId) && WDA_RUNNER_BUNDLE_ID !== productBundleIdentifier) {
Expand All @@ -397,7 +388,7 @@ class WebDriverAgent {
if (actualUpgradeTimestamp && upgradedAt && _.toLower(`${actualUpgradeTimestamp}`) !== _.toLower(`${upgradedAt}`)) {
log.info('Will uninstall running WDA since it has different version in comparison to the one ' +
`which is bundled with appium-xcuitest-driver module (${actualUpgradeTimestamp} != ${upgradedAt})`);
return await this.uninstall(productBundleIdentifier);
return await this.uninstall();
}

const message = util.hasValue(productBundleIdentifier)
Expand All @@ -409,33 +400,34 @@ class WebDriverAgent {

/**
* Quit and uninstall running WDA.
* Uninstall given updatedWDABundleId, 'WDA_RUNNER_BUNDLE_ID' or running 'productBundleIdentifier
* for Xcode 11. Uninstall 'WDA_BUNDLE_ID' for Xcode 10-.
*
* If it fails to get 'await this.getStatus()', it will try to read
* bundle id from plist by WDA.
*/
async quitAndUninstall () {
let bundleId = util.hasValue(this.updatedWDABundleId)
? this.updatedWDABundleId
: WDA_RUNNER_BUNDLE_ID;
await this.quit();
await this.uninstall();
}

const status = await this.getStatus();
if (status && status.build) {
const { productBundleIdentifier } = status.build;
if (util.hasValue(productBundleIdentifier)) {
bundleId = productBundleIdentifier;
}
} else {
const parsedBundleId = await getCFBundleIdentifierFromPlist(
{isRealDevice: this.isRealDevice, platformName: this.platformName}, this.bootstrapPath);
if (util.hasValue(parsedBundleId)) {
bundleId = parsedBundleId;
/**
* Get WDA bundleIds installed in the target device.
* Over Xcode 11, multiple WDA can be in a device since Xcode 11
* set their bundleIds as 'xxxxxx.xctrunner'.
*
* @returns {Array<string>} A list of User level apps' bundle ids which has
* 'CFBundleName' attribute as 'WebDriverAgentRunner-Runner'.
*/
async getInstalledWDBundleId () {
const service = await services.startInstallationProxyService(this.device.udid);
try {
const applications = await service.listApplications({applicationType: 'User'});
const bundleIds = [];
for (const [key, value] of Object.entries(applications)) {
if (value.CFBundleName === WDA_CF_BUNDLE_NAME) {
bundleIds.push(key);
}
}
return bundleIds;
} finally {
service.close();
}

await this.quit();
await this.uninstall(bundleId);
}
}

Expand Down
36 changes: 1 addition & 35 deletions test/unit/wda/utils-specs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getXctestrunFilePath, getAdditionalRunContent,
getXctestrunFileName, getBundleIdFromInfoPlistPath } from '../../../lib/wda/utils';
getXctestrunFileName } from '../../../lib/wda/utils';
import { PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS } from '../../../lib/desired-caps';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
Expand Down Expand Up @@ -160,38 +160,4 @@ describe('utils', function () {
'WebDriverAgentRunner_tvOS_appletvsimulator10.2.0-x86_64.xctestrun');
});
});

describe('#getBundleIdFromInfoPlistPath', function () {
it('should return ios format, real device', function () {
const platformName = 'iOs';
const deviceInfo = {isRealDevice: true, platformName};

getBundleIdFromInfoPlistPath(deviceInfo, 'path/to/build/product').endsWith(
'path/to/build/product/Debug-iphoneos/WebDriverAgentRunner-Runner.app/Info.plist').should.be.true;
});

it('should return ios format, simulator', function () {
const platformName = 'ios';
const deviceInfo = {isRealDevice: false, platformName};

getBundleIdFromInfoPlistPath(deviceInfo, 'path/to/build/product').endsWith(
'path/to/build/product/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/Info.plist').should.be.true;
});

it('should return tvos format, real device', function () {
const platformName = 'tVos';
const deviceInfo = {isRealDevice: true, platformName};

getBundleIdFromInfoPlistPath(deviceInfo, 'path/to/build/product').endsWith(
'path/to/build/product/Debug-appletvos/WebDriverAgentRunner_tvOS-Runner.app/Info.plist').should.be.true;
});

it('should return tvos format, simulator', function () {
const platformName = 'tvOS';
const deviceInfo = {isRealDevice: false, platformName};

getBundleIdFromInfoPlistPath(deviceInfo, 'path/to/build/product').endsWith(
'path/to/build/product/Debug-appletvsimulator/WebDriverAgentRunner_tvOS-Runner.app/Info.plist').should.be.true;
});
});
});
Loading