This repository was archived by the owner on Dec 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathstartSession.js
More file actions
86 lines (74 loc) · 2.77 KB
/
startSession.js
File metadata and controls
86 lines (74 loc) · 2.77 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
var pkg = require('../package.json'),
request = require('request'),
async = require('async'),
WebdriverIO = require('webdriverio');
module.exports = function() {
var that = this,
done = arguments[arguments.length - 1];
/**
* skip when not using applitools
*/
if(!this.self.usesApplitools || this.self.sessionId) {
return done();
}
async.waterfall([
/**
* get meta information of current session
*/
function(cb) {
that.instance.execute(function() {
return {
useragent: navigator.userAgent,
screenWidth: Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
documentHeight: document.documentElement.scrollHeight
};
}, function(err, res) {
that.useragent = res.value.useragent;
that.displaySize = {
width: that.screenWidth && that.screenWidth.length ? that.screenWidth[0] : res.value.screenWidth,
height: res.value.documentHeight
};
return cb();
});
},
/**
* initialise applitools session
*/
function(cb) {
request({
url: that.self.host + '/api/sessions/running',
qs: {apiKey: that.applitools.apiKey},
method: 'POST',
json: {
'startInfo': {
'envName': that.applitools.baselineName,
'appIdOrName': that.applitools.appName,
'scenarioIdOrName': that.currentArgs.name,
'batchInfo': {
'id': that.applitools.batchId,
'name': that.pagename,
'startedAt': new Date().toISOString()
},
'environment': {
'displaySize': that.displaySize,
'inferred': 'useragent:' + that.useragent
},
'matchLevel': 'Strict',
'agentId': pkg.name + '/' + pkg.version
}
},
headers: that.self.headers,
timeout: that.self.reqTimeout
}, cb);
}
], function(err, res, body) {
if (err || res.statusCode !== 200 && res.statusCode !== 201) {
return done(new WebdriverIO.ErrorHandler.CommandError('Couldn\'t start applitools session'));
}
that.self.sessionId = body.id;
that.self.url = body.url;
that.self.isNew = res.statusCode === 201;
return done();
});
};