-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfspmaps.com.js
104 lines (80 loc) · 2 KB
/
fspmaps.com.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
96
97
98
99
100
101
102
103
104
var Spooky;
try {
Spooky = require('spooky');
} catch (e) {
Spooky = require('../lib/spooky');
}
var Page = function(){
}
Page.prototype.run = function(cb) {
this.stats = {}; //Public statistics property
this.cb = cb;
this.startTime;
this.loadTime;
var self = this;
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start('http://www.fspmaps.com/india');
spooky.then(function () {
this.emit('loaded', 'Hello, from ' + this.evaluate(function () {
return document.title;
}));
});
spooky.then(function () {
this.capture('./outputimages/fspmapsindia.png');
});
spooky.then(function(){
this.emit('finished', 'finished'); //let us know we're done. //This should always be the last spooky.then
});
self.startTime = Date.now();
spooky.run();
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
/*
// Uncomment this block to see all of the things Casper has to say.
// There are a lot.
// He has opinions.
spooky.on('console', function (line) {
console.log(line);
});
*/
spooky.on('loaded', function (greeting) {
self.stats.loadTime = (Date.now() - self.startTime) / 1000; //seconds
self.stats.greeting = greeting;
console.log(greeting);
console.log("Loaded in " + self.stats.loadTime + "ms")
});
spooky.on('imageLoaded', function (imgPath) {
self.stats.imgPath = imgPath;
});
spooky.on('finished', function (imgPath) {
self.cb();
});
spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});
}
Page.prototype.getStats = function(){
//Return the stats property
return this.stats;
}
module.exports = Page;