-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre.js
69 lines (60 loc) · 2.14 KB
/
pre.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
// Default debug level
casper.DEBUG = 0;
casper.picture_count = 1;
// casper.check_reporting_calls = false;
casper.setDebugging = function setDebugging() {
if (casper.cli.has("logs")) {
this.verbose = true;
this.logLevel = "debug";
this.DEBUG = 3;
this.echo("---------------------DEBUG MODE!!!---------------------", "COMMENT");
// Casper passed arguments and options
if (casper.DEBUG > 0) {
require("utils").dump(casper.cli.args);
require("utils").dump(casper.cli.options);
}
}
};
casper.setViewJSErrors = function setViewJSErrors() {
casper.viewJSErrors = true;
if (casper.cli.has("nojs")) {
casper.viewJSErrors = false;
}
};
//Helper to print out js objects when debugging
casper.renderJSON = function renderJSON(what) {
return this.echo(JSON.stringify(what, null, ' '));
};
//Setting up a reporting boolean. The event listener for http requests won't respond with
//reporting checks unless this is set to true within a testcase.
casper.reporting = {
check_reporting_calls : false,
check_headers_for_main : false
};
// In order to test reporting, the reporting object must be added
// DEBUG Level 1 takes pictures
// DEBUG Level 2 prints some urls
// DEBUG Level 3 prints more data
casper.on('resource.requested', function(resource) {
if (this.reporting.check_reporting_calls) {
// this.echo("Reporting calls being checked!");
casper.testReporting(resource, casper.reporting.check_reporting_calls);
}
if (casper.reporting.check_headers_for_main === true) {
// this.echo("Headers being dumped!");
dumpHeaders(resource);
}
});
casper.on("page.error", function(msg, trace) {
if (casper.viewJSErrors) {
if (this.getCurrentUrl().match(/\/artists\//gi)) {
this.test.fail("Javascript Error: " + msg);
this.echo("\n--------------ERROR TRACE-----------------\n" + JSON.stringify(trace, null, 4) + "\n------------------END-------------------\n");
}
else {
this.echo("Javascript errors found on " + this.getCurrentUrl());
}
}
});
casper.setDebugging();
casper.test.done();