@@ -47,13 +47,13 @@ casper.on('resource.received', function(resource) {
47
47
48
48
function capturePageSelectors ( url , grabConfigs , viewports , bitmaps_reference , bitmaps_test , isReference ) {
49
49
50
- var
50
+ var
51
51
screenshotNow = new Date ( ) ,
52
52
screenshotDateTime = screenshotNow . getFullYear ( ) + pad ( screenshotNow . getMonth ( ) + 1 ) + pad ( screenshotNow . getDate ( ) ) + '-' + pad ( screenshotNow . getHours ( ) ) + pad ( screenshotNow . getMinutes ( ) ) + pad ( screenshotNow . getSeconds ( ) ) ;
53
53
54
54
casper . start ( ) ;
55
55
// casper.viewport(1280,1024);
56
-
56
+
57
57
58
58
59
59
casper . each ( grabConfigs , function ( casper , grabConfig , grabConfig_index ) {
@@ -78,26 +78,34 @@ function capturePageSelectors(url,grabConfigs,viewports,bitmaps_reference,bitmap
78
78
this . echo ( 'Screenshots for ' + vp . name + ' (' + vp . viewport . width + 'x' + vp . viewport . height + ')' , 'info' ) ;
79
79
80
80
//HIDE SELECTORS WE WANT TO AVOID
81
- grabConfig . hideSelectors . forEach ( function ( o , i , a ) {
82
- casper . evaluate ( function ( o ) {
83
- Array . prototype . forEach . call ( document . querySelectorAll ( o ) , function ( s , j ) {
84
- s . style . visibility = 'hidden' ;
85
- } ) ;
86
- } , o ) ;
87
- } ) ;
81
+ if ( grabConfig . hasOwnProperty ( 'hideSelectors' ) ) {
82
+ grabConfig . hideSelectors . forEach ( function ( o , i , a ) {
83
+ casper . evaluate ( function ( o ) {
84
+ Array . prototype . forEach . call ( document . querySelectorAll ( o ) , function ( s , j ) {
85
+ s . style . visibility = 'hidden' ;
86
+ } ) ;
87
+ } , o ) ;
88
+ } ) ;
89
+ }
88
90
89
91
//REMOVE UNWANTED SELECTORS FROM RENDER TREE
90
- grabConfig . removeSelectors . forEach ( function ( o , i , a ) {
91
- casper . evaluate ( function ( o ) {
92
- Array . prototype . forEach . call ( document . querySelectorAll ( o ) , function ( s , j ) {
93
- s . style . display = 'none' ;
94
- } ) ;
95
- } , o ) ;
96
- } ) ;
97
-
92
+ if ( grabConfig . hasOwnProperty ( 'removeSelectors' ) ) {
93
+ grabConfig . removeSelectors . forEach ( function ( o , i , a ) {
94
+ casper . evaluate ( function ( o ) {
95
+ Array . prototype . forEach . call ( document . querySelectorAll ( o ) , function ( s , j ) {
96
+ s . style . display = 'none' ;
97
+ } ) ;
98
+ } , o ) ;
99
+ } ) ;
100
+ }
101
+
98
102
//CREATE SCREEN SHOTS AND TEST COMPARE CONFIGURATION (CONFIG FILE WILL BE SAVED WHEN THIS PROCESS RETURNS)
103
+ // If no selectors are provided then set the default 'body'
104
+ if ( ! grabConfig . hasOwnProperty ( 'selectors' ) ) {
105
+ grabConfig . selectors = [ 'body' ] ;
106
+ }
99
107
grabConfig . selectors . forEach ( function ( o , i , a ) {
100
- var cleanedSelectorName = o . replace ( / [ ^ a - z A - Z \d ] / , '' ) ; //remove anything that's not a letter or a number
108
+ var cleanedSelectorName = o . replace ( / [ ^ a - z A - Z \d ] / , '' ) ; //remove anything that's not a letter or a number
101
109
//var cleanedUrl = grabConfig.url.replace(/[^a-zA-Z\d]/,'');//remove anything that's not a letter or a number
102
110
var fileName = grabConfig_index + '_' + i + '_' + cleanedSelectorName + '_' + viewport_index + '_' + vp . name + '.png' ; ;
103
111
@@ -117,11 +125,11 @@ function capturePageSelectors(url,grabConfigs,viewports,bitmaps_reference,bitmap
117
125
118
126
casper . captureSelector ( filePath , o ) ;
119
127
//casper.echo('remote capture to > '+filePath,'info');
120
-
128
+
121
129
} ) ; //end topLevelModules.forEach
122
130
} ) ;
123
-
124
-
131
+
132
+
125
133
} ) ; //end casper.each viewports
126
134
127
135
} ) ; //end casper.each grabConfig
0 commit comments