-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnightwatch-api.js
30 lines (30 loc) · 968 Bytes
/
nightwatch-api.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
var api = {
setProtocol: function(protocol) {
if (protocol === 'https') {
return require("https");
} else {
return require("http");
}
},
request: function(assert, protocol, data, callback, done) {
var http = this.setProtocol(protocol);
var req = http.request(data.options, function(res) {
var chunks = [];
res.on("data", function(chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
callback.call(this, assert, body, done);
});
});
req.end();
},
perform: function(browser, protocol, data, callback) {
var _this = this;
return browser.perform(function(client, done) {
_this.request(client.assert, protocol, data, callback, done);
});
}
};
module.exports = api;