diff --git a/module/VisualCeption.php b/module/VisualCeption.php index 23b5a30..885345d 100755 --- a/module/VisualCeption.php +++ b/module/VisualCeption.php @@ -46,6 +46,10 @@ public function _before (\Codeception\TestCase $test) $this->webDriverModule = $this->getModule("WebDriver"); $this->webDriver = $this->webDriverModule->webDriver; + $jQueryString = file_get_contents(__DIR__ . "/jquery.js"); + $this->webDriver->executeScript($jQueryString); + $this->webDriver->executeScript('jQuery.noConflict();'); + $this->test = $test; } @@ -95,6 +99,16 @@ public function dontSeeVisualChanges ($identifier, $elementID = null, $excludeEl } } + /** + * Inject jQuery.js to the actual site + */ + public function wantToUseJQuery() + { + $jQueryString = file_get_contents(__DIR__ . "/jquery.js"); + $this->webDriver->executeScript($jQueryString); + $this->webDriver->executeScript('jQuery.noConflict();'); + } + /** * Hide an element to set the visibility to hidden * @@ -351,9 +365,23 @@ private function compareImages ($image1, $image2) $imagick1 = new \Imagick($image1); $imagick2 = new \Imagick($image2); - $result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR); - $result[0]->setImageFormat("png"); + $imagick1Size = $imagick1->getImageGeometry(); + $imagick2Size = $imagick2->getImageGeometry(); + $maxWidth = max($imagick1Size['width'], $imagick2Size['width']); + $maxHeight = max($imagick1Size['height'], $imagick2Size['height']); + + $imagick1->extentImage($maxWidth, $maxHeight, 0, 0); + $imagick2->extentImage($maxWidth, $maxHeight, 0, 0); + + try { + $result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR); + $result[0]->setImageFormat("png"); + } catch (\ImagickException $e) { + $this->debug("IMagickException! could not campare image1 ($image1) and image2 ($image2).\nExceptionMessage: " . $e->getMessage()); + $this->fail($e->getMessage() . ", image1 $image1 and image2 $image2."); + } + \PHPUnit_Framework_Assert::assertTrue(true); return $result; } } diff --git a/test/integration/tests/acceptance/NotSameSizeCest.php b/test/integration/tests/acceptance/NotSameSizeCest.php new file mode 100755 index 0000000..baf0e61 --- /dev/null +++ b/test/integration/tests/acceptance/NotSameSizeCest.php @@ -0,0 +1,20 @@ +amOnPage("/VisualCeption/notSameSize.php"); + $I->seeVisualChanges("getRedDiv", "div"); + + $I->wait(1); + + // the test has to be called twice for comparison on the travis server + $I->amOnPage("/VisualCeption/notSameSize.php"); + $I->seeVisualChanges("getRedDiv", "div"); + } +} \ No newline at end of file diff --git a/test/integration/tests/acceptance/TimeComparisonCest.php b/test/integration/tests/acceptance/TimeComparisonCest.php index d648f00..5ddb9e3 100755 --- a/test/integration/tests/acceptance/TimeComparisonCest.php +++ b/test/integration/tests/acceptance/TimeComparisonCest.php @@ -4,7 +4,7 @@ class TimeComparisonCest { /** - * Coparing a div that renders the current time + * Comparing a div that renders the current time */ public function seeVisualChanges (WebGuy $I, $scenario) {