-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcaptureXHRTraffic.js
50 lines (45 loc) · 2.03 KB
/
captureXHRTraffic.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
49
50
const assert = require("assert");
const fs = require('fs');
module.exports = {
'Capture XHR Traffic' : function (browser) {
browser
.url('https://www.test-cors.org/')
.execute(fs.readFileSync('ajaxListener.js').toString())
.waitForElementVisible('body')
.setValue('#server_url', 'https://httpbin.org/get')
.click('#btnSendRequest')
.pause(3000)
.getLog('browser', function(traffics) {
// Write to the traffics.log
fs.writeFileSync('traffics.log', JSON.stringify(traffics, null, 4));
// Parse traffics
traffics.forEach(function(traffic) {
consoleMessage = traffic.message;
try {
jsonObj = JSON.parse(JSON.parse(consoleMessage.substring(18, consoleMessage.length)));
method = jsonObj.method;
url = jsonObj.url;
requestData = jsonObj.requestData;
responseCode = jsonObj.responseCode;
responseHeader = jsonObj.responseHeader;
responseText = jsonObj.responseText;
console.log('**********************');
console.log('method: ' + method);
console.log('url: ' + url);
console.log('requestData: ' + requestData);
console.log('responseCode: ' + responseCode);
console.log('responseHeader: '+ responseHeader);
console.log('responseText: ' + responseText);
console.log('\n');
browser.assert.equal(responseCode, '200')
} catch (err) {
if (err instanceof assert.AssertionError) {
throw err;
} else {
}
}
})
})
.end();
}
};