forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.js
48 lines (42 loc) · 1.4 KB
/
session.js
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
module.exports = class Session {
static get WEB_ELEMENT_ID () {
return 'element-6066-11e4-a52e-4f735466cecf';
}
static serializeCapabilities(caps) {
let ret = {};
for (let key of caps.keys()) {
let cap = caps.get(key);
if (cap !== undefined && cap !== null) {
ret[key] = cap;
}
}
return ret;
}
constructor(driver) {
this.driver = driver;
}
async exported() {
const session = await this.driver.getSession();
const sessionId = await session.getId();
const sessionCapabilities = await session.getCapabilities();
const platform = sessionCapabilities.getPlatform() || sessionCapabilities.get('platform') || '';
const platformVersion = sessionCapabilities.get('platformVersion') || '';
const browserName = sessionCapabilities.getBrowserName();
const browserVersion = sessionCapabilities.getBrowserVersion() || sessionCapabilities.get('version') || '';
const appId = sessionCapabilities.get('appPackage') || sessionCapabilities.get('bundleId') || '';
const executor = await this.driver.getExecutor();
const elementKey = executor.w3c ? Session.WEB_ELEMENT_ID : 'ELEMENT';
return {
sessionId,
elementKey,
sessionInfo: {
platform,
platformVersion,
browserName,
browserVersion,
appId
},
capabilities: Session.serializeCapabilities(sessionCapabilities)
};
}
};