Skip to content

Commit 0af4cc4

Browse files
authored
feat: use isIos18OrNewer to check version instead of ios-device util (#2716)
* use `isIos18OrNewer` to check version instead of ios-device util * make `driverOpts` non-optional param
1 parent 2ced29f commit 0af4cc4

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

lib/device/real-device-management.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {buildSafariPreferences, SAFARI_BUNDLE_ID} from '../app-utils';
77
import {log as defaultLogger} from '../logger';
88
import { Devicectl } from 'node-devicectl';
99
import type { AppiumLogger } from '@appium/types';
10-
import type { XCUITestDriver } from '../driver';
10+
import type { XCUITestDriver, XCUITestDriverOpts } from '../driver';
1111
import {AfcClient} from './afc-client';
12+
import {isIos18OrNewer} from '../utils';
1213

1314
const DEFAULT_APP_INSTALLATION_TIMEOUT_MS = 8 * 60 * 1000;
1415
export const IO_TIMEOUT_MS = 4 * 60 * 1000;
@@ -264,10 +265,11 @@ export class RealDevice {
264265
readonly udid: string;
265266
private readonly _log: AppiumLogger;
266267
readonly devicectl: Devicectl;
267-
private platformVersion: string | undefined;
268+
readonly driverOpts: XCUITestDriverOpts;
268269

269-
constructor(udid: string, logger?: AppiumLogger) {
270+
constructor(udid: string, driverOpts: XCUITestDriverOpts, logger?: AppiumLogger) {
270271
this.udid = udid;
272+
this.driverOpts = driverOpts;
271273
this._log = logger ?? defaultLogger;
272274
this.devicectl = new Devicectl(this.udid);
273275
}
@@ -294,8 +296,7 @@ export class RealDevice {
294296
timeoutMs = IO_TIMEOUT_MS,
295297
} = opts;
296298
const timer = new timing.Timer().start();
297-
const platformVersion = await this.getPlatformVersion();
298-
const useRemoteXPC = !!platformVersion && util.compareVersions(platformVersion, '>=', '18.0');
299+
const useRemoteXPC = isIos18OrNewer(this.driverOpts);
299300
const afcClient = await AfcClient.createForDevice(this.udid, useRemoteXPC);
300301
try {
301302
let bundlePathOnPhone: string;
@@ -516,10 +517,7 @@ export class RealDevice {
516517
}
517518

518519
async getPlatformVersion(): Promise<string> {
519-
if (!this.platformVersion) {
520-
this.platformVersion = await utilities.getOSVersion(this.udid) as string;
521-
}
522-
return this.platformVersion;
520+
return await utilities.getOSVersion(this.udid);
523521
}
524522

525523
async reset(opts: {bundleId?: string; fullReset?: boolean}): Promise<void> {

lib/driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ export class XCUITestDriver
13621362
}
13631363

13641364
this.log.debug(`Creating iDevice object with udid '${this.opts.udid}'`);
1365-
const device = new RealDevice(this.opts.udid as string, this.log);
1365+
const device = new RealDevice(this.opts.udid as string, this.opts, this.log);
13661366
return {device, realDevice: true, udid: this.opts.udid as string};
13671367
}
13681368

test/unit/commands/location-specs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sinon from 'sinon';
2-
import {XCUITestDriver} from '../../../lib/driver';
2+
import {XCUITestDriver, XCUITestDriverOpts} from '../../../lib/driver';
33
import {services} from 'appium-ios-device';
44
import {RealDevice} from '../../../lib/device/real-device-management';
55
import {expect} from 'chai';
@@ -77,7 +77,7 @@ describe('location commands', function () {
7777
describe('on real device', function () {
7878
beforeEach(function () {
7979
driver.opts.udid = udid;
80-
driver._device = new RealDevice('123');
80+
driver._device = new RealDevice('123', {} as XCUITestDriverOpts);
8181
});
8282

8383
it('should use location service to set a location when no platform version', async function () {

test/unit/driver-specs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import xcode from 'appium-xcode';
22
import {JWProxy} from 'appium/driver';
33
import _ from 'lodash';
44
import {createSandbox} from 'sinon';
5-
import {XCUITestDriver} from '../../lib/driver';
5+
import {XCUITestDriver, XCUITestDriverOpts} from '../../lib/driver';
66
import * as utils from '../../lib/utils';
77
import {MOCHA_LONG_TIMEOUT} from './helpers';
88
import {RealDevice} from '../../lib/device/real-device-management';
@@ -39,7 +39,7 @@ describe('XCUITestDriver', function () {
3939

4040
beforeEach(function () {
4141
driver = new XCUITestDriver({} as any);
42-
realDevice = new RealDevice('1234');
42+
realDevice = new RealDevice('1234', {} as XCUITestDriverOpts);
4343
// Mock _wda to avoid getter throwing error
4444
// For simulators, url.port should be undefined to allow wdaLocalPort to be used
4545
driver._wda = {

test/unit/real-device-management-specs.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createSandbox} from 'sinon';
22
import { installToRealDevice, RealDevice } from '../../lib/device/real-device-management';
3-
import {XCUITestDriver} from '../../lib/driver';
3+
import {XCUITestDriver, XCUITestDriverOpts} from '../../lib/driver';
44
import chai, {expect} from 'chai';
55
import chaiAsPromised from 'chai-as-promised';
66
import type {SinonStub} from 'sinon';
@@ -25,7 +25,7 @@ describe('installToRealDevice', function () {
2525
});
2626

2727
it('nothing happen without app', async function () {
28-
const realDevice = new RealDevice(udid);
28+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
2929
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
3030
const installStub = sandbox.stub(realDevice, 'install').resolves() as SinonStub;
3131
driver.opts = {udid};
@@ -37,7 +37,7 @@ describe('installToRealDevice', function () {
3737
});
3838

3939
it('nothing happen without bundle id', async function () {
40-
const realDevice = new RealDevice(udid);
40+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
4141
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
4242
const installStub = sandbox.stub(realDevice, 'install').resolves() as SinonStub;
4343
driver._device = realDevice;
@@ -52,7 +52,7 @@ describe('installToRealDevice', function () {
5252
const opts = {
5353
skipUninstall: true
5454
};
55-
const realDevice = new RealDevice(udid);
55+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
5656
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
5757
const installStub = sandbox.stub(realDevice, 'install').resolves() as SinonStub;
5858
driver._device = realDevice;
@@ -68,7 +68,7 @@ describe('installToRealDevice', function () {
6868
const opts = {
6969
skipUninstall: false
7070
};
71-
const realDevice = new RealDevice(udid);
71+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
7272
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
7373
const installStub = sandbox.stub(realDevice, 'install').resolves() as SinonStub;
7474
driver._device = realDevice;
@@ -85,7 +85,7 @@ describe('installToRealDevice', function () {
8585
skipUninstall: false
8686
};
8787
const err_msg = `{"Error":"ApplicationVerificationFailed","ErrorDetail":-402620395,"ErrorDescription":"Failed to verify code signature of /path/to.app : 0xe8008015 (A valid provisioning profile for this executable was not found.)"}`;
88-
const realDevice = new RealDevice(udid);
88+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
8989
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
9090
const installStub = sandbox.stub(realDevice, 'install').throws(err_msg) as SinonStub;
9191
driver._device = realDevice;
@@ -102,7 +102,7 @@ describe('installToRealDevice', function () {
102102
const opts = {
103103
skipUninstall: true
104104
};
105-
const realDevice = new RealDevice(udid);
105+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
106106
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
107107
const installStub = sandbox.stub(realDevice, 'install')
108108
.onCall(0).throws(`{"Error":"MismatchedApplicationIdentifierEntitlement","ErrorDescription":"Upgrade's application-identifier entitlement string (TEAM_ID.com.kazucocoa.example) does not match installed application's application-identifier string (ANOTHER_TEAM_ID.com.kazucocoa.example); rejecting upgrade."}`)
@@ -121,7 +121,7 @@ describe('installToRealDevice', function () {
121121
skipUninstall: true
122122
};
123123
const err_msg = `{"Error":"ApplicationVerificationFailed","ErrorDetail":-402620395,"ErrorDescription":"Failed to verify code signature of /path/to.app : 0xe8008015 (A valid provisioning profile for this executable was not found.)"}`;
124-
const realDevice = new RealDevice(udid);
124+
const realDevice = new RealDevice(udid, {} as XCUITestDriverOpts);
125125
const removeStub = sandbox.stub(realDevice, 'remove').resolves() as SinonStub;
126126
const installStub = sandbox.stub(realDevice, 'install').throws(err_msg) as SinonStub;
127127
sandbox.stub(realDevice, 'isAppInstalled').resolves(true);

0 commit comments

Comments
 (0)