Skip to content

Commit 57a70ea

Browse files
Added tool to boot simulator
Co-authored-by: SrinivasanTarget <[email protected]>
1 parent dd0ef26 commit 57a70ea

File tree

4 files changed

+96
-9
lines changed

4 files changed

+96
-9
lines changed

src/devicemanager/ios-manager.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,9 @@ export class IOSManager {
109109

110110
/**
111111
* Get all available iOS simulators
112-
* Prioritizes booted simulators, but returns all if none are booted
113-
* @returns Array of iOS simulators
112+
* @returns Array of all iOS simulators (both booted and shutdown)
114113
*/
115114
public async getAvailableSimulators(): Promise<IOSDevice[]> {
116-
const bootedSimulators = await this.listBootedSimulators();
117-
118-
if (bootedSimulators.length > 0) {
119-
return bootedSimulators;
120-
}
121-
122-
// If no booted simulators, return all available simulators
123115
return await this.listSimulators();
124116
}
125117

src/tools/boot-simulator.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Tool to boot iOS simulator
3+
*/
4+
import { z } from 'zod';
5+
import { Simctl } from 'node-simctl';
6+
import { IOSManager } from '../devicemanager/ios-manager.js';
7+
8+
export default function bootSimulator(server: any): void {
9+
server.addTool({
10+
name: 'boot_simulator',
11+
description:
12+
'Boot an iOS simulator and wait for it to be ready. This speeds up subsequent session creation by ensuring the simulator is already running.',
13+
parameters: z.object({
14+
udid: z
15+
.string()
16+
.describe(
17+
'The UDID of the iOS simulator to boot. Use select_platform and select_device tools first to get the UDID.'
18+
),
19+
}),
20+
annotations: {
21+
readOnlyHint: false,
22+
openWorldHint: false,
23+
},
24+
execute: async (args: any, context: any): Promise<any> => {
25+
try {
26+
const { udid } = args;
27+
28+
// Verify it's a macOS system
29+
if (process.platform !== 'darwin') {
30+
throw new Error('iOS simulators can only be booted on macOS systems');
31+
}
32+
33+
const iosManager = IOSManager.getInstance();
34+
const simulators = await iosManager.listSimulators();
35+
36+
// Find the simulator with the given UDID
37+
const simulator = simulators.find(sim => sim.udid === udid);
38+
39+
if (!simulator) {
40+
throw new Error(
41+
`Simulator with UDID "${udid}" not found. Please use select_platform and select_device tools to get a valid UDID.`
42+
);
43+
}
44+
45+
// Check current state
46+
if (simulator.state === 'Booted') {
47+
return {
48+
content: [
49+
{
50+
type: 'text',
51+
text: `✅ Simulator "${simulator.name}" is already booted and ready!\n\nUDID: ${udid}\niOS Version: ${simulator.platform || 'Unknown'}\nState: ${simulator.state}`,
52+
},
53+
],
54+
};
55+
}
56+
57+
console.log(`Booting iOS simulator: ${simulator.name} (${udid})...`);
58+
59+
const simctl = new Simctl();
60+
simctl.udid = udid;
61+
62+
// Boot the device
63+
await simctl.bootDevice();
64+
console.log(
65+
'Simulator boot initiated, waiting for boot to complete...'
66+
);
67+
68+
// Wait for boot to complete with 2 minute timeout
69+
await simctl.startBootMonitor({ timeout: 120000 });
70+
71+
console.log(`Simulator "${simulator.name}" booted successfully!`);
72+
73+
return {
74+
content: [
75+
{
76+
type: 'text',
77+
text: `✅ Simulator booted successfully!\n\nDevice: ${simulator.name}\nUDID: ${udid}\niOS Version: ${simulator.platform || 'Unknown'}\n\n🚀 The simulator is now ready for session creation. You can now use the create_session tool to start an Appium session.`,
78+
},
79+
],
80+
};
81+
} catch (error: any) {
82+
console.error('Error booting simulator:', error);
83+
throw new Error(`Failed to boot simulator: ${error.message}`);
84+
}
85+
},
86+
});
87+
}

src/tools/create-session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export default function createSession(server: any): void {
166166
...(platformVersion && {
167167
'appium:platformVersion': platformVersion,
168168
}),
169+
// Add WDA optimization for simulators
170+
...(deviceType === 'simulator' && {
171+
'appium:usePrebuiltWDA': true,
172+
'appium:wdaStartupRetries': 4,
173+
'appium:wdaStartupRetryInterval': 20000,
174+
}),
169175
...customCapabilities,
170176
};
171177

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import uploadApp from './upload-app.js';
77
import generateLocators from './locators.js';
88
import selectPlatform from './select-platform.js';
99
import selectDevice from './select-device.js';
10+
import bootSimulator from './boot-simulator.js';
1011
import generateTest from './generate-tests.js';
1112
import scroll from './scroll.js';
1213
import scrollToElement from './scroll-to-element.js';
@@ -24,6 +25,7 @@ import listApps from './interactions/listApps.js';
2425
export default function registerTools(server: FastMCP): void {
2526
selectPlatform(server);
2627
selectDevice(server);
28+
bootSimulator(server);
2729
createSession(server);
2830
deleteSession(server);
2931
createCloudSession(server);

0 commit comments

Comments
 (0)