Skip to content

Commit f85ffce

Browse files
improve typing
1 parent d2b0df9 commit f85ffce

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

lib/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {type HTTPHeaders} from '@appium/types';
2+
import type {Simctl} from 'node-simctl';
3+
import type {Devicectl} from 'node-devicectl';
24

35
// WebDriverAgentLib/Utilities/FBSettings.h
46
export interface WDASettings {
@@ -99,8 +101,8 @@ export interface WebDriverAgentArgs {
99101

100102
export interface AppleDevice {
101103
udid: string;
102-
simctl?: any;
103-
devicectl?: any;
104+
simctl?: Simctl;
105+
devicectl?: Devicectl;
104106
[key: string]: any;
105107
}
106108

lib/webdriveragent.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
} from './constants';
2323
import {strongbox} from '@appium/strongbox';
2424
import type {WebDriverAgentArgs, AppleDevice} from './types';
25+
import type {Simctl} from 'node-simctl';
26+
import type {Devicectl} from 'node-devicectl';
2527

2628
const WDA_LAUNCH_TIMEOUT = 60 * 1000;
2729
const WDA_AGENT_PORT = 8100;
@@ -361,7 +363,11 @@ export class WebDriverAgent {
361363
if (this.usePreinstalledWDA) {
362364
this.log.info('Stopping the XCTest session');
363365
try {
364-
await this.device.simctl.terminateApp(this.bundleIdForXctest);
366+
if (this.device.simctl) {
367+
await this.device.simctl.terminateApp(this.bundleIdForXctest);
368+
} else if (this.device.devicectl) {
369+
await this.device.devicectl.terminateApp(this.bundleIdForXctest);
370+
}
365371
} catch (e: any) {
366372
this.log.warn(e.message);
367373
}
@@ -372,8 +378,7 @@ export class WebDriverAgent {
372378
}
373379
} else {
374380
this.log.debug(
375-
'Do not stop xcodebuild nor XCTest session ' +
376-
'since the WDA session is managed by outside this driver.',
381+
'Stopping neither xcodebuild nor XCTest session since WDA lifecycle is not managed by this driver',
377382
);
378383
}
379384

@@ -662,7 +667,7 @@ export class WebDriverAgent {
662667
): Promise<void> {
663668
const {env} = opts;
664669

665-
await this.device.devicectl.launchApp(this.bundleIdForXctest, {env, terminateExisting: true});
670+
await (this.device.devicectl as Devicectl).launchApp(this.bundleIdForXctest, {env, terminateExisting: true});
666671
}
667672

668673
/**
@@ -684,7 +689,7 @@ export class WebDriverAgent {
684689
if (this.isRealDevice) {
685690
await this._launchViaDevicectl({env: xctestEnv});
686691
} else {
687-
await this.device.simctl.exec('launch', {
692+
await (this.device.simctl as Simctl).exec('launch', {
688693
args: ['--terminate-running-process', this.device.udid, this.bundleIdForXctest],
689694
env: xctestEnv,
690695
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"chai-as-promised": "^8.0.0",
6666
"conventional-changelog-conventionalcommits": "^9.0.0",
6767
"mocha": "^11.0.1",
68+
"node-devicectl": "^1.4.0",
6869
"node-simctl": "^8.0.0",
6970
"prettier": "^3.0.0",
7071
"semantic-release": "^25.0.2",

test/unit/webdriveragent-specs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import * as utils from '../../lib/utils';
66
import path from 'node:path';
77
import sinon from 'sinon';
88
import type {WebDriverAgentArgs} from '../../lib/types';
9+
import type {Simctl} from 'node-simctl';
10+
import type {Devicectl} from 'node-devicectl';
911

1012
chai.use(chaiAsPromised);
1113

1214
const fakeConstructorArgs: WebDriverAgentArgs = {
1315
device: {
1416
udid: 'some-sim-udid',
15-
simctl: {},
16-
devicectl: {},
17+
simctl: {} as Simctl,
18+
devicectl: {} as Devicectl,
1719
},
1820
platformVersion: '9',
1921
host: 'me',

0 commit comments

Comments
 (0)