| 16 | } |
| 17 | |
| 18 | export class WDAManager extends BaseServiceManager { |
| 19 | private static instances = new Map<string, WDAManager>(); |
| 20 | private config: WDAConfig; |
| 21 | private isStarted = false; |
| 22 | |
| 23 | private constructor(config: WDAConfig) { |
| 24 | super(config.port, config.host); |
| 25 | this.config = { |
| 26 | bundleId: 'com.apple.WebDriverAgentRunner.xctrunner', |
| 27 | usePrebuiltWDA: true, |
| 28 | host: 'localhost', |
| 29 | ...config, |
| 30 | port: config.port || DEFAULT_WDA_PORT, |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | static getInstance(port = DEFAULT_WDA_PORT, host?: string): WDAManager { |
| 35 | const key = `${host || 'localhost'}:${port}`; |
| 36 | if (!WDAManager.instances.has(key)) { |
| 37 | WDAManager.instances.set(key, new WDAManager({ port, host })); |
| 38 | } |
| 39 | return WDAManager.instances.get(key)!; |
| 40 | } |
| 41 | |
| 42 | async start(): Promise<void> { |
| 43 | if (this.isStarted) { |
| 44 | debugWDA( |
| 45 | `WDA already started on ${this.config.host}:${this.config.port}`, |
| 46 | ); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | try { |
| 51 | // Check if WDA is already running on the port |
| 52 | if (await this.isWDARunning()) { |
| 53 | debugWDA(`WDA already running on port ${this.config.port}`); |
| 54 | this.isStarted = true; |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // Note: Device connection and port forwarding are handled externally |
| 59 | // We only check if WebDriverAgent is running |
| 60 | |
| 61 | // Start WebDriverAgent |
| 62 | await this.startWDA(); |
| 63 | |
| 64 | // Wait for WDA to be ready |
| 65 | await this.waitForWDA(); |
| 66 | |
| 67 | this.isStarted = true; |
| 68 | debugWDA( |
| 69 | `WDA started successfully on ${this.config.host}:${this.config.port}`, |
| 70 | ); |
| 71 | } catch (error) { |
| 72 | debugWDA(`Failed to start WDA: ${error}`); |
| 73 | throw new Error(`Failed to start WebDriverAgent: ${error}`); |
| 74 | } |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected