-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshots-example.js
88 lines (79 loc) · 1.77 KB
/
screenshots-example.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
// screenshots-test.js
// makes screenshots of page http://www.ksymena.com.pl
var casper = require('casper').create();
var viewports = [{
'name': '320',
'viewport': {
width: 320,
height: 600
}
}, {
'name': '480',
'viewport': {
width: 480,
height: 600
}
}, {
'name': '640',
'viewport': {
width: 640,
height: 600
}
}, {
'name': '768',
'viewport': {
width: 768,
height: 800
}
}, {
'name': '980',
'viewport': {
width: 980,
height: 800
}
}, {
'name': '1024',
'viewport': {
width: 1024,
height: 800
}
}, {
'name': '1200',
'viewport': {
width: 1200,
height: 800
}
}, {
'name': '1400',
'viewport': {
width: 1400,
height: 800
}
}];
if (casper.cli.args.length < 1) {
casper.echo("Usage example: 'casperjs screenshots-test.js http://ksymena.com.pl'").exit(1);
} else {
screenshotUrl = casper.cli.args[0];
}
casper.start();
casper.each(viewports, function(casper, viewport) {
this.then(function() {
this.viewport(viewport.viewport.width, viewport.viewport.height);
});
this.thenOpen(screenshotUrl, function() {
this.wait(1000);
});
this.then(function() {
this.echo('Processing: ' + viewport.name + ' (' + viewport.viewport.width + 'x' + viewport.viewport.height + ')', 'info');
this.capture('screenshots/' + viewport.name + '-' + viewport.viewport.width + 'x' + viewport.viewport.height + '.png', {
top: 0,
left: 0,
width: viewport.viewport.width,
height: viewport.viewport.height
});
});
});
casper.then(function() {
this.echo("Processing done!");
});
casper.run();