-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoot-page.js
95 lines (82 loc) · 2.2 KB
/
shoot-page.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
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
87
88
89
90
91
92
93
94
95
var page = require("webpage").create();
var config = require("./config");
page.viewportSize = config.viewportSize;
page.customHeaders = config.customHeaders;
var loadStart = Date.now();
var loadEnd = Date.now();
var navigation = [];
page.navigationRequested = function(url, type) {
navigation.push({
url: url,
type: type
});
};
var resources = {};
page.onResourceRequested = function(request) {
resources[request.id] = {
id: request.id,
url: request.url,
start: Date.now()
};
};
page.onResourceReceived = function(response) {
resources[response.id].status = response.status;
resources[response.id].end = Date.now();
resources[response.id].bodySize = response.bodySize;
loadEnd = Date.now();
};
page.onResourceTimeout = function(request) {
resources[request.id].end = Date.now();
resources[request.id].timedout = true;
loadEnd = Date.now();
};
page.onResourceError = function(resourceError) {
resources[resourceError.id].end = Date.now();
resources[resourceError.id].error = true;
resources[resourceError.id].errorCode = resourceError.errorCode;
resources[resourceError.id].errorString = resourceError.errorString;
loadEnd = Date.now();
};
var consoleMessages = [];
page.onConsoleMessage = function(message, lineNumber, sourceId) {
consoleMessages.push({
message: message,
lineNumber: lineNumber,
sourceId: sourceId,
timestamp: Date.now()
});
};
var errors = [];
page.onError = function(message, stackTrace) {
errors.push({
message: message,
stackTrace: stackTrace
});
loadEnd = Date.now();
};
function reportPageShot() {
var imageName = "screenshots/" + Date.now() + ".png";
page.render(imageName);
var pageShotReport = {
loadStart: loadStart,
loadEnd: loadEnd,
pageUrl: config.pageUrl,
viewportSize: config.viewportSize,
customHeaders: config.customHeaders,
imageName: imageName,
resources: resources,
navigation: navigation,
consoleMessages: consoleMessages,
errors: errors
};
console.log(JSON.stringify(pageShotReport, " ", 2));
console.log("#####");
}
function shootPage() {
page.open(config.pageUrl);
setTimeout(function() {
reportPageShot();
phantom.exit();
}, 30000);
}
shootPage();