Skip to content

Commit

Permalink
chore: include devicectl in IOSDeploy object (#2352)
Browse files Browse the repository at this point in the history
* chore: include devicectl in IOSDeploy object

* add ignore

* define once to reduce ignore

* define once to reduce ignore

* mofidy log
  • Loading branch information
KazuCocoa authored Mar 25, 2024
1 parent e393989 commit 6c5abd1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
11 changes: 6 additions & 5 deletions lib/commands/memory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import { Devicectl } from '../devicectl';
import { errors } from 'appium/driver';

export default {
Expand All @@ -16,9 +15,11 @@ export default {
throw new Error('Memory warning simulation is only supported on real devices');
}

const devicectl = new Devicectl(this.opts.udid, this.log);
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
const device = this.opts.device;

/** @type {import('../devicectl').AppInfo[]} */
const appInfos = await devicectl.listApps(bundleId);
const appInfos = await device.devicectl.listApps(bundleId);
if (_.isEmpty(appInfos)) {
throw new errors.InvalidArgumentError(
`The application identified by ${bundleId} cannot be found on the device. Is it installed?`
Expand All @@ -36,7 +37,7 @@ export default {
// allow to connect a bundle id to a process id.
const pattern = new RegExp(`^${_.escapeRegExp(appInfos[0].url)}[^/]+$`);
/** @type {number[]} */
const pids = (await devicectl.listProcesses())
const pids = (await device.devicectl.listProcesses())
.filter(({executable}) => pattern.test(executable))
.map(({processIdentifier}) => processIdentifier);
if (_.isEmpty(pids)) {
Expand All @@ -45,7 +46,7 @@ export default {
);
}
this.log.info(`Emulating Low Memory warning for the process id ${pids[0]}, bundle id ${bundleId}`);
await devicectl.sendMemoryWarning(pids[0]);
await device.devicectl.sendMemoryWarning(pids[0]);
}
};

Expand Down
9 changes: 5 additions & 4 deletions lib/commands/xctest-record-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'lodash';
import {fs, util} from 'appium/support';
import {encodeBase64OrUpload} from '../utils';
import path from 'node:path';
import {Devicectl} from '../devicectl';

const MOV_EXT = '.mov';
const FEATURE_NAME = 'xctest_screen_record';
Expand Down Expand Up @@ -60,8 +59,10 @@ async function retrieveRecodingFromSimulator(uuid) {
* @returns {Promise<string>} The full path to the screen recording movie
*/
async function retrieveRecodingFromRealDevice(uuid) {
const devicectl = new Devicectl(this.opts.udid, this.log);
const fileNames = await devicectl.listFiles(DOMAIN_TYPE, DOMAIN_IDENTIFIER, {
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
const device = this.opts.device;

const fileNames = await device.devicectl.listFiles(DOMAIN_TYPE, DOMAIN_IDENTIFIER, {
username: USERNAME,
subdirectory: SUBDIRECTORY,
});
Expand All @@ -71,7 +72,7 @@ async function retrieveRecodingFromRealDevice(uuid) {
);
}
const videoPath = path.join(/** @type {string} */ (this.opts.tmpDir), `${uuid}${MOV_EXT}`);
await devicectl.pullFile(`${SUBDIRECTORY}/${uuid}`, videoPath, {
await device.devicectl.pullFile(`${SUBDIRECTORY}/${uuid}`, videoPath, {
username: USERNAME,
domainIdentifier: DOMAIN_IDENTIFIER,
domainType: DOMAIN_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ class XCUITestDriver extends BaseDriver {
}
}

const device = getRealDeviceObj(this.opts.udid);
const device = getRealDeviceObj(this.opts.udid, this.log);
return {device, realDevice: true, udid: this.opts.udid};
}

Expand Down
5 changes: 3 additions & 2 deletions lib/real-device-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ async function installToRealDevice(device, app, bundleId, opts) {

/**
* @param {string} udid
* @param {import('@appium/types').AppiumLogger} logger
* @returns {RealDevice}
*/
function getRealDeviceObj(udid) {
function getRealDeviceObj(udid, logger) {
log.debug(`Creating iDevice object with udid '${udid}'`);
return new RealDevice(udid);
return new RealDevice(udid, logger);
}

export {
Expand Down
8 changes: 4 additions & 4 deletions lib/real-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const APP_INSTALL_STRATEGY = Object.freeze({
});

class RealDevice {
constructor(udid) {
constructor(udid, logger) {
this.udid = udid;
this.devicectl = new Devicectl(this.udid, logger);
}

async remove(bundleId) {
Expand Down Expand Up @@ -211,15 +212,14 @@ class RealDevice {
if (util.compareVersions(platformVersion, '>=', '17.0')) {
log.debug(`Calling devicectl to kill the process`);

const devicectl = new Devicectl(this.udid, log);
const pids = (await devicectl.listProcesses())
const pids = (await this.devicectl.listProcesses())
.filter(({executable}) => executable.endsWith(`/${executableName}`))
.map(({processIdentifier}) => processIdentifier);
if (_.isEmpty(pids)) {
log.info(`The process of the bundle id '${bundleId}' was not running`);
return false;
}
await devicectl.sendSignalToProcess(pids[0], 2);
await this.devicectl.sendSignalToProcess(pids[0], 2);
} else {
instrumentService = await services.startInstrumentService(this.udid);
const processes = await instrumentService.callChannel(
Expand Down

0 comments on commit 6c5abd1

Please sign in to comment.