@@ -2,6 +2,7 @@ var fs = require('fs');
2
2
var path = require ( 'path' ) ;
3
3
var getPixels = require ( "get-pixels" ) ;
4
4
var images = require ( 'images' ) ;
5
+ var n = 0 ; //截图次数
5
6
6
7
var commonTools = ( {
7
8
@@ -70,22 +71,22 @@ var commonTools = ({
70
71
console . log ( 'invalid input : type or exampleName is not a string' ) ;
71
72
return ;
72
73
}
73
- screenShotPath = './examples-test/output/' + type + '_' + exampleName + '.png' ;
74
- tileTestPath = './examples-test/output/' + type + '_' + exampleName + 'TileTest .png' ;
74
+ screenShotPath = './examples-test/output/' + type + '_' + exampleName + '_' + n + ' .png';
75
+ tileTestPath = './examples-test/output/' + type + '_' + exampleName + 'TileTest_' + n + ' .png';
75
76
tileStandardPath = './examples-test/' + type + '/resources/' + exampleName + '.png' ;
76
77
browser . pause ( 5000 ) ;
77
78
browser . saveScreenshot ( screenShotPath , function ( ) {
78
- console . log ( 'start to get the tile' ) ;
79
+ console . log ( 'start to get test tile' ) ;
79
80
var totalWidth = images ( screenShotPath ) . width ( ) ;
80
81
var totalHeight = images ( screenShotPath ) . height ( ) ;
81
82
var offX = ( totalWidth - width ) / 2 + offsetX ;
82
83
var offY = ( totalHeight - height ) / 2 - offsetY ;
83
84
commonTools . getTileFromScreenshot ( screenShotPath , offX , offY , width , height , tileTestPath ) ;
84
- console . log ( 'get the tile completed' ) ;
85
+ console . log ( 'get test tile completed' ) ;
85
86
} ) ;
86
87
browser . pause ( 5000 , function ( ) {
87
- console . log ( 'start to compare two tiles ' ) ;
88
- commonTools . isTwoTilesEqual ( browser , tileStandardPath , tileTestPath ) ;
88
+ console . log ( 'start to compare test tile with standard tile ' ) ;
89
+ commonTools . isTwoTilesEqual ( browser , tileStandardPath , tileTestPath , type , exampleName , offsetX , offsetY , width , height ) ;
89
90
} ) ;
90
91
} ,
91
92
@@ -94,21 +95,23 @@ var commonTools = ({
94
95
* offX, offY: Offset relative to the top-left corner
95
96
* */
96
97
getTileFromScreenshot : function ( sourceImagePath , offX , offY , width , height , tilePath ) {
97
- images ( images ( sourceImagePath ) , offX , offY , width , height )
98
- . save ( tilePath ) ;
98
+ images ( images ( sourceImagePath ) , offX , offY , width , height ) . save ( tilePath ) ;
99
99
} ,
100
100
101
101
/*
102
102
* function: compare two image by tilePath,
103
103
* return : boolean
104
104
* */
105
- isTwoTilesEqual : function ( browser , tilePath1 , tilePath2 ) {
105
+ isTwoTilesEqual : function ( browser , tilePath1 , tilePath2 , type , exampleName , offsetX , offsetY , width , height ) {
106
+ browser . pause ( 2000 , function ( ) {
107
+ n ++ ;
108
+ } ) ;
106
109
var array1 = [ ] ;
107
110
var array2 = [ ] ;
108
111
console . log ( 'start to compare two tiles' ) ;
109
112
getPixels ( tilePath1 , function ( err , pixels ) {
110
113
if ( err ) {
111
- browser . assert . ok ( false , "path in tile1 not exist: " + tilePath1 ) ;
114
+ browser . assert . ok ( false , "path of standard tile not exist: " + tilePath1 ) ;
112
115
return ;
113
116
}
114
117
for ( var i = 0 ; i < pixels . data . length ; i ++ ) {
@@ -117,18 +120,29 @@ var commonTools = ({
117
120
console . log ( 'tile1 ( ' + tilePath1 + ' ) has pixels : ' + ( array1 . length / 4 ) ) ;
118
121
getPixels ( tilePath2 , function ( err , pixels ) {
119
122
if ( err ) {
120
- browser . assert . ok ( false , "path in tile2 not exist: " + tilePath2 ) ;
123
+ browser . assert . ok ( false , "path of test tile not exist: " + tilePath2 ) ;
121
124
return ;
122
125
}
123
126
for ( var i = 0 ; i < pixels . data . length ; i ++ ) {
124
127
array2 . push ( pixels . data [ i ] ) ;
125
128
}
126
129
console . log ( 'tile2 ( ' + tilePath2 + ' ) has pixels : ' + ( array2 . length / 4 ) ) ;
127
130
var isEqual = commonTools . judgeTwoTilesByRgbaArrays ( browser , array1 , array2 ) ;
131
+ //判断两张图是否相等
128
132
if ( isEqual ) {
129
- browser . assert . ok ( isEqual , 'similarity of two pictures >= 0.9' ) ;
130
- } else {
131
- browser . assert . ok ( isEqual , 'similarity of two pictures < 0.9' ) ;
133
+ n = 0 ;
134
+ browser . assert . ok ( isEqual , '第' + n + '次比较,similarity of two pictures >=0.9' ) ;
135
+ }
136
+ else if ( n > 4 ) {
137
+ n = 0 ;
138
+ browser . assert . ok ( isEqual , '4次比较后,similarity of two pictures <0.9' ) ;
139
+ }
140
+ else {
141
+ console . log ( '第' + n + '次比较,地图不相等,继续比较...' ) ;
142
+ browser . deleteCookies ( function ( ) {
143
+ commonTools . openExampleAndLoadMap ( browser , type , exampleName ) ;
144
+ commonTools . cmpTestTileWithStdTile ( browser , type , exampleName , offsetX , offsetY , width , height ) ;
145
+ } ) ;
132
146
}
133
147
} ) ;
134
148
} ) ;
@@ -145,7 +159,7 @@ var commonTools = ({
145
159
console . log ( 'length are not equal' ) ;
146
160
return false ;
147
161
}
148
- console . log ( 'length are equal' ) ;
162
+ console . log ( 'length of two tiles are equal' ) ;
149
163
var totalCount = ( ( RgbaArraysOfTile1 . length ) / 4 ) ;
150
164
var unEqualCount = commonTools . difPixelsCount ( RgbaArraysOfTile1 , RgbaArraysOfTile2 ) ;
151
165
console . log ( 'different pixels count : ' + unEqualCount ) ;
@@ -194,6 +208,7 @@ var commonTools = ({
194
208
195
209
/*leaflet: verify correctness of copyright*/
196
210
verifyCopyrightOfLeaflet : function ( browser ) {
211
+ browser . pause ( 1000 ) ;
197
212
//iClient logo
198
213
browser . useXpath ( ) . click ( '//*[@id="map"]/div[2]/div[4]/div[1]/a' ) ;
199
214
browser . pause ( 1000 ) ;
0 commit comments