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 2 commits
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
23 changes: 11 additions & 12 deletions lib/real-device-management.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utilities, services } from 'appium-ios-device';
import IOSDeploy from './ios-deploy';
import log from './logger';

import _ from 'lodash';

async function getConnectedDevices () {
return await utilities.getConnectedDevices();
Expand Down Expand Up @@ -72,28 +72,27 @@ function getRealDeviceObj (udid) {
*/

/**
* @param {RealDevice} The real device object which has 'udid' attribute
* @param {string} cFBundleName The name of CFBundleName in Info.plist
* @param {RealDevice} device The real device object which has 'udid' attribute
* @param {string} bundleName The name of CFBundleName in Info.plist
*
* @returns {Array<string>} A list of User level apps' bundle ids which has
* 'CFBundleName' attribute as 'cFBundleName'.
* 'CFBundleName' attribute as 'bundleName'.
*/
async function getIBundleIdsByCFBundleName (device, cFBundleName) {
async function getBundleIdsByBundleName (device, bundleName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, lets move this method into IOSDeploy class

const service = await services.startInstallationProxyService(device.udid);
try {
const applications = await service.listApplications({applicationType: 'User'});
const bundleIds = [];
for (const [key, value] of Object.entries(applications)) {
if (value.CFBundleName === cFBundleName) {
bundleIds.push(key);
return _.reduce(applications, (acc, {CFBundleName}, key) => {
if (CFBundleName === bundleName) {
acc.push(key);
}
}
return bundleIds;
return acc;
}, []);
} finally {
service.close();
}
}


export { getConnectedDevices, getOSVersion, runRealDeviceReset, installToRealDevice,
getRealDeviceObj, getIBundleIdsByCFBundleName };
getRealDeviceObj, getBundleIdsByBundleName };
5 changes: 3 additions & 2 deletions lib/simulator-management.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import B from 'bluebird';
import path from 'path';
import { getSimulator } from 'appium-ios-simulator';
import { createDevice, getDevices, terminate, shutdown } from 'node-simctl';
Expand Down Expand Up @@ -216,11 +217,11 @@ async function shutdownOtherSimulators (currentDevice) {

async function getInstalledBundleIds (device, candidateBundleIds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually change this in appium-ios-simulator that we get a similar api like what the real devices have? This would help us get rid of having a list of potential bundle ids

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Aug 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can either add this call to ios simulator or we can attach it to the object dynamically right in this module:

this.device.getInstalledBundleIds = getInstalledBundleIds.bind(this.device);

Then this context in this method will be pointing to device instance if called from this.device.getInstalledBundleIds(...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about something else. I'm talking about making this method similar as the getBundleIdsByBundleName (device, bundleName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^
This one as well. Otherwise how can it be polymorphic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is an oneliner then we could simply move it to getInstalledWDBundleId

const bundleIds = [];
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
for (const bundleId of candidateBundleIds) {
await B.filter(candidateBundleIds, async (bundleId) => {
if (await device.isAppInstalled(bundleId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really - the filter condition should be async (bundleId) => await device.isAppInstalled(bundleId)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the result could be returned immediately. There is no need for the intermediate accumulator

bundleIds.push(bundleId);
}
}
});
return bundleIds;
}

Expand Down
9 changes: 5 additions & 4 deletions lib/wda/webdriveragent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import B from 'bluebird';
import _ from 'lodash';
import path from 'path';
import url from 'url';
Expand All @@ -12,7 +13,7 @@ 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 { getIBundleIdsByCFBundleName } from '../real-device-management';
import { getBundleIdsByBundleName } from '../real-device-management';
import { getInstalledBundleIds } from '../simulator-management';

const WDA_LAUNCH_TIMEOUT = 60 * 1000;
Expand Down Expand Up @@ -174,9 +175,9 @@ class WebDriverAgent {
}

log.debug(`Uninstalling WDAs: '${bundleIds}'`);
for (const bundleId of bundleIds) {
await B.each(bundleIds, async (bundleId) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here I would revert back to for of. each call does not provide any preferences over a normal loop

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 @@ -422,7 +423,7 @@ class WebDriverAgent {
*/
async getInstalledWDBundleId () {
return this.isRealDevice
? await getIBundleIdsByCFBundleName(this.device, WDA_CF_BUNDLE_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how about moving these methods into corresponding classes and make it polymorphic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I also thought we can get CFBundleNam in simulator case (ios-simulator does not have such a method for now tho) as future work

? await getBundleIdsByBundleName(this.device, WDA_CF_BUNDLE_NAME)
: await getInstalledBundleIds(this.device, [WDA_BUNDLE_ID, WDA_BUNDLE_ID_XCODE11]);
}
}
Expand Down