Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions module/VisualCeption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
20 changes: 20 additions & 0 deletions test/integration/tests/acceptance/NotSameSizeCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class NotSameSizeCest
{

/**
* Comparing a div, that change it's size
*/
public function seeVisualChangesAfterSizeChanges(WebGuy $I, $scenario)
{
$I->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");
}
}
2 changes: 1 addition & 1 deletion test/integration/tests/acceptance/TimeComparisonCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down