@@ -2,6 +2,7 @@ var fs = require('fs');
22var path = require ( 'path' ) ;
33var getPixels = require ( "get-pixels" ) ;
44var images = require ( 'images' ) ;
5+ var n = 0 ; //截图次数
56
67var commonTools = ( {
78
@@ -70,22 +71,22 @@ var commonTools = ({
7071 console . log ( 'invalid input : type or exampleName is not a string' ) ;
7172 return ;
7273 }
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';
7576 tileStandardPath = './examples-test/' + type + '/resources/' + exampleName + '.png' ;
7677 browser . pause ( 5000 ) ;
7778 browser . saveScreenshot ( screenShotPath , function ( ) {
78- console . log ( 'start to get the tile' ) ;
79+ console . log ( 'start to get test tile' ) ;
7980 var totalWidth = images ( screenShotPath ) . width ( ) ;
8081 var totalHeight = images ( screenShotPath ) . height ( ) ;
8182 var offX = ( totalWidth - width ) / 2 + offsetX ;
8283 var offY = ( totalHeight - height ) / 2 - offsetY ;
8384 commonTools . getTileFromScreenshot ( screenShotPath , offX , offY , width , height , tileTestPath ) ;
84- console . log ( 'get the tile completed' ) ;
85+ console . log ( 'get test tile completed' ) ;
8586 } ) ;
8687 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 ) ;
8990 } ) ;
9091 } ,
9192
@@ -94,21 +95,23 @@ var commonTools = ({
9495 * offX, offY: Offset relative to the top-left corner
9596 * */
9697 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 ) ;
9999 } ,
100100
101101 /*
102102 * function: compare two image by tilePath,
103103 * return : boolean
104104 * */
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+ } ) ;
106109 var array1 = [ ] ;
107110 var array2 = [ ] ;
108111 console . log ( 'start to compare two tiles' ) ;
109112 getPixels ( tilePath1 , function ( err , pixels ) {
110113 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 ) ;
112115 return ;
113116 }
114117 for ( var i = 0 ; i < pixels . data . length ; i ++ ) {
@@ -117,18 +120,29 @@ var commonTools = ({
117120 console . log ( 'tile1 ( ' + tilePath1 + ' ) has pixels : ' + ( array1 . length / 4 ) ) ;
118121 getPixels ( tilePath2 , function ( err , pixels ) {
119122 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 ) ;
121124 return ;
122125 }
123126 for ( var i = 0 ; i < pixels . data . length ; i ++ ) {
124127 array2 . push ( pixels . data [ i ] ) ;
125128 }
126129 console . log ( 'tile2 ( ' + tilePath2 + ' ) has pixels : ' + ( array2 . length / 4 ) ) ;
127130 var isEqual = commonTools . judgeTwoTilesByRgbaArrays ( browser , array1 , array2 ) ;
131+ //判断两张图是否相等
128132 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+ } ) ;
132146 }
133147 } ) ;
134148 } ) ;
@@ -145,7 +159,7 @@ var commonTools = ({
145159 console . log ( 'length are not equal' ) ;
146160 return false ;
147161 }
148- console . log ( 'length are equal' ) ;
162+ console . log ( 'length of two tiles are equal' ) ;
149163 var totalCount = ( ( RgbaArraysOfTile1 . length ) / 4 ) ;
150164 var unEqualCount = commonTools . difPixelsCount ( RgbaArraysOfTile1 , RgbaArraysOfTile2 ) ;
151165 console . log ( 'different pixels count : ' + unEqualCount ) ;
@@ -194,6 +208,7 @@ var commonTools = ({
194208
195209 /*leaflet: verify correctness of copyright*/
196210 verifyCopyrightOfLeaflet : function ( browser ) {
211+ browser . pause ( 1000 ) ;
197212 //iClient logo
198213 browser . useXpath ( ) . click ( '//*[@id="map"]/div[2]/div[4]/div[1]/a' ) ;
199214 browser . pause ( 1000 ) ;
0 commit comments