-
Notifications
You must be signed in to change notification settings - Fork 0
/
createSession.ts
65 lines (56 loc) · 1.88 KB
/
createSession.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { BaseDriver } from '@appium/base-driver';
import type {
DefaultCreateSessionResult,
DriverData,
W3CDriverCaps,
} from '@appium/types';
import { URL } from 'url';
import { HtmlDriver } from '../Driver.js';
import { DevToolsDevice } from '../adapters/DevToolsDevice.js';
import { InstrumentedDevice } from '../adapters/InstrumentedDevice.js';
import { capabilitiesConstraints } from '../capabilitiesConstraints.js';
import { getNamespace } from '../helpers/server.js';
export async function createSession(
this: HtmlDriver,
w3cCaps1: W3CDriverCaps<typeof capabilitiesConstraints>,
w3cCaps2?: W3CDriverCaps<typeof capabilitiesConstraints>,
w3cCaps3?: W3CDriverCaps<typeof capabilitiesConstraints>,
driverData?: DriverData[]
): Promise<DefaultCreateSessionResult<typeof capabilitiesConstraints>> {
const session = await BaseDriver.prototype.createSession.call(
this,
w3cCaps1,
w3cCaps2,
w3cCaps3,
driverData
);
const url = new URL(this.opts.debuggingAddress);
if (url.protocol === 'ws:') {
this.remote = new DevToolsDevice();
await this.remote.open({ target: this.opts.debuggingAddress });
} else if (url.protocol === 'odc:') {
const matches = this.opts.debuggingAddress.match(
/^odc:\/\/([^\/]+)\/?([^\/#?]+)/
);
if (!matches) {
throw new Error(
`Invalid odc debugging address: ${this.opts.debuggingAddress}`
);
}
const udid = matches[1];
const handle = matches[2];
this.opts.udid = udid;
// @ts-ignore `server` is a hidden property
const namespace = getNamespace(this.server, udid);
this.remote = new InstrumentedDevice();
await this.remote.open({ socket: namespace.server, udid });
if (handle) {
await this.remote.setSession(handle);
}
} else {
throw new Error(
`Unsupported debugging protocol: ${url.protocol.slice(0, -1)}`
);
}
return session;
}