Skip to content

Commit 224e2b0

Browse files
author
Neubert, Sebastian
committed
#4 Allow comparisson of images that do not have the same size
1 parent 22ead78 commit 224e2b0

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

module/VisualCeption.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,20 @@ 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+
$maxWidth = max($imagick1->getImageGeometry()['width'], $imagick2->getImageGeometry()['width']);
369+
$maxHeight = max($imagick1->getImageGeometry()['height'], $imagick2->getImageGeometry()['height']);
370+
371+
$imagick1->extentImage($maxWidth, $maxHeight, 0, 0);
372+
$imagick2->extentImage($maxWidth, $maxHeight, 0, 0);
356373

374+
try {
375+
$result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR);
376+
$result[0]->setImageFormat("png");
377+
} catch (\ImagickException $e) {
378+
$this->debug("ImageMagickException! could not campare image1 ($image1) and image2 ($image2).\nExceptionMessage: " . $e->getMessage());
379+
$this->fail($e->getMessage() . ", image1 $image1 and image2 $image2.");
380+
}
381+
\PHPUnit_Framework_Assert::assertTrue(true);
357382
return $result;
358383
}
359384
}

0 commit comments

Comments
 (0)