@@ -46,6 +46,10 @@ public function _before (\Codeception\TestCase $test)
4646 $ this ->webDriverModule = $ this ->getModule ("WebDriver " );
4747 $ this ->webDriver = $ this ->webDriverModule ->webDriver ;
4848
49+ $ jQueryString = file_get_contents (__DIR__ . "/jquery.js " );
50+ $ this ->webDriver ->executeScript ($ jQueryString );
51+ $ this ->webDriver ->executeScript ('jQuery.noConflict(); ' );
52+
4953 $ this ->test = $ test ;
5054 }
5155
@@ -95,6 +99,16 @@ public function dontSeeVisualChanges ($identifier, $elementID = null, $excludeEl
9599 }
96100 }
97101
102+ /**
103+ * Inject jQuery.js to the actual site
104+ */
105+ public function wantToUseJQuery ()
106+ {
107+ $ jQueryString = file_get_contents (__DIR__ . "/jquery.js " );
108+ $ this ->webDriver ->executeScript ($ jQueryString );
109+ $ this ->webDriver ->executeScript ('jQuery.noConflict(); ' );
110+ }
111+
98112 /**
99113 * Hide an element to set the visibility to hidden
100114 *
@@ -351,9 +365,23 @@ private function compareImages ($image1, $image2)
351365 $ imagick1 = new \Imagick ($ image1 );
352366 $ imagick2 = new \Imagick ($ image2 );
353367
354- $ result = $ imagick1 ->compareImages ( $ imagick2 , \Imagick:: METRIC_MEANSQUAREERROR );
355- $ result [ 0 ]-> setImageFormat ( " png " );
368+ $ imagick1Size = $ imagick1 ->getImageGeometry ( );
369+ $ imagick2Size = $ imagick2 -> getImageGeometry ( );
356370
371+ $ maxWidth = max ($ imagick1Size ['width ' ], $ imagick2Size ['width ' ]);
372+ $ maxHeight = max ($ imagick1Size ['height ' ], $ imagick2Size ['height ' ]);
373+
374+ $ imagick1 ->extentImage ($ maxWidth , $ maxHeight , 0 , 0 );
375+ $ imagick2 ->extentImage ($ maxWidth , $ maxHeight , 0 , 0 );
376+
377+ try {
378+ $ result = $ imagick1 ->compareImages ($ imagick2 , \Imagick::METRIC_MEANSQUAREERROR );
379+ $ result [0 ]->setImageFormat ("png " );
380+ } catch (\ImagickException $ e ) {
381+ $ this ->debug ("IMagickException! could not campare image1 ( $ image1) and image2 ( $ image2). \nExceptionMessage: " . $ e ->getMessage ());
382+ $ this ->fail ($ e ->getMessage () . ", image1 $ image1 and image2 $ image2. " );
383+ }
384+ \PHPUnit_Framework_Assert::assertTrue (true );
357385 return $ result ;
358386 }
359387}
0 commit comments