(
lease: DeviceLease,
req?: DaemonRequest,
)
| 213 | } |
| 214 | |
| 215 | private async allocate( |
| 216 | lease: DeviceLease, |
| 217 | req?: DaemonRequest, |
| 218 | ): Promise<Record<string, unknown> | undefined> { |
| 219 | if (lease.leaseProvider !== this.provider) return undefined; |
| 220 | if (this.sessionsByLeaseId.has(lease.leaseId)) return this.heartbeat(lease); |
| 221 | const prepared = await this.prepareSession(lease, req); |
| 222 | const client = new WebDriverClient({ |
| 223 | endpoint: prepared.endpoint, |
| 224 | auth: prepared.auth, |
| 225 | headers: prepared.headers, |
| 226 | requestPolicy: this.options.requestPolicy, |
| 227 | }); |
| 228 | const session = await this.createSessionWithPreparedCleanup(client, prepared); |
| 229 | const device = this.deviceForLease(lease, prepared); |
| 230 | const providerSessionId = prepared.providerSessionId ?? session.sessionId; |
| 231 | const capabilities = this.capabilitiesForPlatform(prepared.platform); |
| 232 | this.sessionsByLeaseId.set(lease.leaseId, { |
| 233 | lease, |
| 234 | device, |
| 235 | client, |
| 236 | prepared, |
| 237 | capabilities, |
| 238 | webDriverSessionId: session.sessionId, |
| 239 | providerSessionId, |
| 240 | interactor: createWebDriverInteractor({ |
| 241 | client, |
| 242 | backend: snapshotBackendForPlatform(prepared.platform), |
| 243 | capabilities, |
| 244 | }), |
| 245 | }); |
| 246 | return { |
| 247 | provider: this.provider, |
| 248 | deviceId: device.id, |
| 249 | sessionId: session.sessionId, |
| 250 | providerSessionId, |
| 251 | capabilities, |
| 252 | ...prepared.providerData, |
| 253 | }; |
| 254 | } |
| 255 | |
| 256 | private async createSessionWithPreparedCleanup( |
| 257 | client: WebDriverClient, |
no test coverage detected