Skip to content

Commit ff9879c

Browse files
Merge pull request #30 from sebastianneubert/master
#4 Allow comparisson of images that do not have the same size
2 parents 31dfc0f + 28d4057 commit ff9879c

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

module/VisualCeption.php

Lines changed: 30 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,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
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class NotSameSizeCest
4+
{
5+
6+
/**
7+
* Comparing a div, that change it's size
8+
*/
9+
public function seeVisualChangesAfterSizeChanges(WebGuy $I, $scenario)
10+
{
11+
$I->amOnPage("/VisualCeption/notSameSize.php");
12+
$I->seeVisualChanges("getRedDiv", "div");
13+
14+
$I->wait(1);
15+
16+
// the test has to be called twice for comparison on the travis server
17+
$I->amOnPage("/VisualCeption/notSameSize.php");
18+
$I->seeVisualChanges("getRedDiv", "div");
19+
}
20+
}

test/integration/tests/acceptance/TimeComparisonCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class TimeComparisonCest
44
{
55

66
/**
7-
* Coparing a div that renders the current time
7+
* Comparing a div that renders the current time
88
*/
99
public function seeVisualChanges (WebGuy $I, $scenario)
1010
{

0 commit comments

Comments
 (0)