diff --git a/.gitignore b/.gitignore
index baf6b9d..05fabf3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,11 @@
.buildpath
.project
.settings/
+.idea/
+.idea/*
+.idea
+
+.DS_Store
+._.DS_Store
+test/integration/tests/_log/
+test/integration/tests/acceptance/WebGuy.php
diff --git a/module/Html/Manipulation.php b/module/Html/Manipulation.php
new file mode 100755
index 0000000..a974cf6
--- /dev/null
+++ b/module/Html/Manipulation.php
@@ -0,0 +1,77 @@
+webDriver = $webDriver;
+ $this->injectJQuery();
+ }
+
+ /**
+ * This function injects jQuery into the website
+ */
+ private function injectJQuery()
+ {
+ $jQueryString = file_get_contents(__DIR__ . "/jquery.js");
+ $this->webDriver->executeScript($jQueryString);
+ $this->webDriver->executeScript('jQuery.noConflict();');
+ }
+
+ /**
+ * This function hides the given divs from the website.
+ *
+ * @param array $elements
+ */
+ public function hideElements(array $elements)
+ {
+ foreach ($elements as $element) {
+ $this->hideElement($element);
+ }
+ $this->webDriver->wait(1);
+ }
+
+ /**
+ * Hide an element to set the visibility to hidden
+ *
+ * @param $elementSelector String of jQuery Element selector, set visibility to hidden
+ */
+ private function hideElement($elementSelector)
+ {
+ $this->webDriver->executeScript('
+ if( jQuery("' . $elementSelector . '").length > 0 ) {
+ jQuery( "' . $elementSelector . '" ).css("visibility","hidden");
+ }
+ ');
+ }
+
+ /**
+ * Show an element to set the visibility to visible
+ *
+ * @param $elementSelector String of jQuery Element selector, set visibility to visible
+ */
+ private function showElement($elementSelector)
+ {
+ $this->webDriver->executeScript('
+ if( jQuery("' . $elementSelector . '").length > 0 ) {
+ jQuery( "' . $elementSelector . '" ).css("visibility","visible");
+ }
+ ');
+ }
+
+ /**
+ * Reset hiding the given elements with CSS visibility = visible. Wait a second after reset hiding
+ *
+ * @param array $excludeElements array of strings, which should be visible again
+ */
+ private function showElements(array $elements)
+ {
+ foreach ($elements as $element) {
+ $this->showElement($element);
+ }
+ $this->webDriver->wait(1);
+ }
+}
\ No newline at end of file
diff --git a/module/Html/Screenshot.php b/module/Html/Screenshot.php
new file mode 100755
index 0000000..5b5d049
--- /dev/null
+++ b/module/Html/Screenshot.php
@@ -0,0 +1,46 @@
+webDriver = $webDriver;
+ }
+
+ public function takeScreenshot($jqueryIdentifier = "body")
+ {
+ $image = new \Imagick();
+ $image->readimageblob($this->webDriver->takeScreenshot());
+
+ $coords = $this->getCoordinates($jqueryIdentifier);
+
+ $image->cropImage($coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y']);
+
+ return $image;
+ }
+
+ private function getCoordinates($jqueryIdentifier)
+ {
+ $jQueryString = file_get_contents(__DIR__ . "/jquery.js");
+ $this->webDriver->executeScript($jQueryString);
+ $this->webDriver->executeScript('jQuery.noConflict();');
+
+ $imageCoords = array();
+
+ $elementExists = (bool)$this->webDriver->executeScript('return jQuery( "' . $jqueryIdentifier . '" ).length > 0;');
+
+ if (!$elementExists) {
+ throw new \Exception("The element you want to examine ('" . $jqueryIdentifier . "') was not found.");
+ }
+
+ $imageCoords['offset_x'] = (string)$this->webDriver->executeScript('return jQuery( "' . $jqueryIdentifier . '" ).offset().left;');
+ $imageCoords['offset_y'] = (string)$this->webDriver->executeScript('return jQuery( "' . $jqueryIdentifier . '" ).offset().top;');
+ $imageCoords['width'] = (string)$this->webDriver->executeScript('return jQuery( "' . $jqueryIdentifier . '" ).width();');
+ $imageCoords['height'] = (string)$this->webDriver->executeScript('return jQuery( "' . $jqueryIdentifier . '" ).height();');
+
+ return $imageCoords;
+ }
+}
\ No newline at end of file
diff --git a/module/jquery.js b/module/Html/jquery.js
similarity index 100%
rename from module/jquery.js
rename to module/Html/jquery.js
diff --git a/module/Image/Comparison.php b/module/Image/Comparison.php
new file mode 100755
index 0000000..2aab5e7
--- /dev/null
+++ b/module/Image/Comparison.php
@@ -0,0 +1,28 @@
+getImageGeometry();
+ $imagick2Size = $image2->getImageGeometry();
+
+ $maxWidth = max($imagick1Size['width'], $imagick2Size['width']);
+ $maxHeight = max($imagick1Size['height'], $imagick2Size['height']);
+
+ $image1->extentImage($maxWidth, $maxHeight, 0, 0);
+ $image2->extentImage($maxWidth, $maxHeight, 0, 0);
+
+ $result = $image1->compareImages($image2, \Imagick::METRIC_MEANSQUAREERROR);
+ $result[0]->setImageFormat('png');
+
+ return new \ComparisonResult(round($result[1] * 100, 2), $image1, $image2, $result[0]);
+ }
+}
\ No newline at end of file
diff --git a/module/Image/ComparisonResult.php b/module/Image/ComparisonResult.php
new file mode 100755
index 0000000..7596a9e
--- /dev/null
+++ b/module/Image/ComparisonResult.php
@@ -0,0 +1,47 @@
+currentImage = $currentImage;
+ $this->expectedImage = $expectedImage;
+
+ $this->deviation = $deviation;
+ $this->comparionImage = $comparisonImage;
+ }
+
+ public function getDeviation()
+ {
+ return $this->deviation;
+ }
+
+ /**
+ * @return Imagick
+ */
+ public function getDeviationImage()
+ {
+ return $this->comparionImage;
+ }
+
+ /**
+ * @return Imagick
+ */
+ public function getExpectedImage()
+ {
+ return $this->expectedImage;
+ }
+
+ /**
+ * @return Imagick
+ */
+ public function getCurrentImage()
+ {
+ return $this->currentImage;
+ }
+}
\ No newline at end of file
diff --git a/module/ImageDeviationException.php b/module/ImageDeviationException.php
index 454c4ac..c58143a 100755
--- a/module/ImageDeviationException.php
+++ b/module/ImageDeviationException.php
@@ -4,31 +4,31 @@
class ImageDeviationException extends \PHPUnit_Framework_ExpectationFailedException
{
- private $expectedImage;
- private $currentImage;
- private $deviationImage;
+ private $result;
+ private $storage;
+ private $identifier;
- public function __construct($message, $expectedImage, $currentImage, $deviationImage)
+ public function __construct($message, \ComparisonResult $comparisonResult, \Storage $storage, $identifier = "leer")
{
- $this->deviationImage = $deviationImage;
- $this->currentImage = $currentImage;
- $this->expectedImage = $expectedImage;
+ $this->result = $comparisonResult;
+ $this->storage = $storage;
+ $this->identifier = $identifier;
parent::__construct($message);
}
- public function getDeviationImage( )
+ public function getComparisonResult()
{
- return $this->deviationImage;
+ return $this->result;
}
- public function getCurrentImage()
+ public function getStorage()
{
- return $this->currentImage;
+ return $this->storage;
}
- public function getExpectedImage()
+ public function getIdentifier()
{
- return $this->expectedImage;
+ return $this->identifier;
}
}
\ No newline at end of file
diff --git a/module/Report/ci_template.php b/module/Report/ci_template.php
new file mode 100755
index 0000000..4169669
--- /dev/null
+++ b/module/Report/ci_template.php
@@ -0,0 +1,44 @@
+
+
+
+
+ VisualCeption Report
+
+
+
+
+
+
+
+
+
+ Deviation Image
+
+
+
+
+ Expected Image
+
+
+
+
+ Current Image
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/module/report/template.php b/module/Report/template.php
similarity index 74%
rename from module/report/template.php
rename to module/Report/template.php
index b6adedb..680ba6f 100755
--- a/module/report/template.php
+++ b/module/Report/template.php
@@ -11,17 +11,17 @@
Deviation Image
-
+
Expected Image
-
+
Current Image
-
+
diff --git a/module/Storage/Factory.php b/module/Storage/Factory.php
new file mode 100755
index 0000000..7ba75b3
--- /dev/null
+++ b/module/Storage/Factory.php
@@ -0,0 +1,29 @@
+storageDir = $config["expectedImageDir"];
+ } else {
+ $this->storageDir = \Codeception\Configuration::dataDir() . 'VisualCeption/expected/';
+ }
+ }
+
+ /**
+ * Returns the filename of the images connected to the identifier
+ *
+ * @param string $identifier the validation identifier
+ * @return string the image file
+ */
+ private function getStorageFile($identifier)
+ {
+ return $this->storageDir . $identifier . ".png";
+ }
+
+ /**
+ * Returns the image (Imagick) connected to the identifier
+ *
+ * @param string $identifier the validation identifier
+ * @return Imagick
+ */
+ public function getImage($identifier)
+ {
+ $imageFile = $this->getStorageFile($identifier);
+ if( !file_exists($imageFile)) {
+ $image = new \Imagick();
+ $image->newImage(1, 1, new ImagickPixel('white'));
+ return $image;
+ }
+ return new \Imagick($imageFile);
+ }
+
+ public function setImage(\Imagick $image, $identifier)
+ {
+ $filename = $this->getStorageFile($identifier);
+ return $image->writeImage($filename);
+ }
+}
\ No newline at end of file
diff --git a/module/Storage/RemoteStorage.php b/module/Storage/RemoteStorage.php
new file mode 100755
index 0000000..03ce8df
--- /dev/null
+++ b/module/Storage/RemoteStorage.php
@@ -0,0 +1,49 @@
+userId = $config["userId"];
+ $this->storageServer = $config["expectedImageServer"];
+ }
+
+ public function getStorageFile($identifier)
+ {
+ return $this->storageServer . '?userId=' . $this->userId . '&imageId=' . $identifier;
+ }
+
+ public function getImage($identifier) {
+ // @todo use curl
+ $imageFile = $this->getStorageFile($identifier);
+ $imageContent = file_get_contents($imageFile);
+
+ $image = new \Imagick();
+ $image->readimageblob($imageContent);
+
+ return $image;
+ }
+
+ public function setImage(\Imagick $image, $identifier)
+ {
+ $url = $this->getStorageFile($identifier);
+
+ $ch = curl_init();
+
+ $imageContent = base64_encode($image->getimageblob());
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "image=" . $imageContent);
+
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ $server_output = curl_exec ($ch);
+
+ var_dump($server_output);
+
+ curl_close ($ch);
+ }
+}
\ No newline at end of file
diff --git a/module/Storage/Storage.php b/module/Storage/Storage.php
new file mode 100755
index 0000000..22e5c93
--- /dev/null
+++ b/module/Storage/Storage.php
@@ -0,0 +1,6 @@
+config)) {
+ $this->maximumDeviation = $this->config["maximumDeviation"];
+ }
+
+ $this->storageStrategy = \Factory::getStorage($this->config);
+ }
+
/**
* Event hook before a test starts
*
@@ -54,20 +66,7 @@ public function _before(\Codeception\TestCase $test)
if (!$this->hasModule("WebDriver")) {
throw new \Exception("VisualCeption uses the WebDriver. Please be sure that this module is activated.");
}
-
- $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;
- }
-
- public function getReferenceImageDir()
- {
- return $this->referenceImageDir;
+ $this->webDriver = $this->getModule("WebDriver")->webDriver;
}
/**
@@ -78,26 +77,14 @@ public function getReferenceImageDir()
* @param string $elementID DOM ID of the element, which should be screenshotted
* @param string|array $excludeElements Element name or array of Element names, which should not appear in the screenshot
*/
- public function seeVisualChanges($identifier, $elementID = null, $excludeElements = array())
+ public function seeVisualChanges($identifier, $elementId = null, $excludedElements = array())
{
- $excludeElements = (array)$excludeElements;
-
- $deviationResult = $this->getDeviation($identifier, $elementID, $excludeElements);
-
- if (!is_null($deviationResult["deviationImage"])) {
+ $comparisonResult = $this->getVisualChanges($identifier, $elementId, (array)$excludedElements);
- // used for assertion counter in codeception / phpunit
+ if($comparisonResult->getDeviation() <= $this->maximumDeviation ) {
$this->assertTrue(true);
-
- if ($deviationResult["deviation"] <= $this->maximumDeviation) {
- $compareScreenshotPath = $this->getDeviationScreenshotPath($identifier);
- $deviationResult["deviationImage"]->writeImage($compareScreenshotPath);
-
- throw new ImageDeviationException("The deviation of the taken screenshot is too low (" . $deviationResult["deviation"] . "%).\nSee $compareScreenshotPath for a deviation screenshot.",
- $this->getExpectedScreenshotPath($identifier),
- $this->getScreenshotPath($identifier),
- $compareScreenshotPath);
- }
+ throw new ImageDeviationException("The deviation of the taken screenshot is too low (" . $comparisonResult->getDeviation() . "%)",
+ $comparisonResult, $this->storageStrategy, $identifier);
}
}
@@ -109,332 +96,41 @@ public function seeVisualChanges($identifier, $elementID = null, $excludeElement
* @param string $elementID DOM ID of the element, which should be screenshotted
* @param string|array $excludeElements string of Element name or array of Element names, which should not appear in the screenshot
*/
- public function dontSeeVisualChanges($identifier, $elementID = null, $excludeElements = array())
+ public function dontSeeVisualChanges($identifier, $elementId = null, $excludedElements = array())
{
- $excludeElements = (array)$excludeElements;
+ $comparisonResult = $this->getVisualChanges($identifier, $elementId, (array)$excludedElements);
- $deviationResult = $this->getDeviation($identifier, $elementID, $excludeElements);
-
- if (!is_null($deviationResult["deviationImage"])) {
-
- // used for assertion counter in codeception / phpunit
+ if($comparisonResult->getDeviation() > $this->maximumDeviation ) {
$this->assertTrue(true);
-
- if ($deviationResult["deviation"] > $this->maximumDeviation) {
- $compareScreenshotPath = $this->getDeviationScreenshotPath($identifier);
- $deviationResult["deviationImage"]->writeImage($compareScreenshotPath);
-
- throw new ImageDeviationException("The deviation of the taken screenshot is too hight (" . $deviationResult["deviation"] . "%).\nSee $compareScreenshotPath for a deviation screenshot.",
- $this->getExpectedScreenshotPath($identifier),
- $this->getScreenshotPath($identifier),
- $compareScreenshotPath);
- }
- }
- }
-
- /**
- * Hide an element to set the visibility to hidden
- *
- * @param $elementSelector String of jQuery Element selector, set visibility to hidden
- */
- private function hideElement($elementSelector)
- {
- $this->webDriver->executeScript('
- if( jQuery("' . $elementSelector . '").length > 0 ) {
- jQuery( "' . $elementSelector . '" ).css("visibility","hidden");
- }
- ');
- $this->debug("set visibility of element '$elementSelector' to 'hidden'");
- }
-
- /**
- * Show an element to set the visibility to visible
- *
- * @param $elementSelector String of jQuery Element selector, set visibility to visible
- */
- private function showElement($elementSelector)
- {
- $this->webDriver->executeScript('
- if( jQuery("' . $elementSelector . '").length > 0 ) {
- jQuery( "' . $elementSelector . '" ).css("visibility","visible");
- }
- ');
- $this->debug("set visibility of element '$elementSelector' to 'visible'");
- }
-
- /**
- * Compares the two images and calculate the deviation between expected and actual image
- *
- * @param string $identifier Identifies your test object
- * @param string $elementID DOM ID of the element, which should be screenshotted
- * @param array $excludeElements Element names, which should not appear in the screenshot
- * @return array Includes the calculation of deviation in percent and the diff-image
- */
- private function getDeviation($identifier, $elementID, array $excludeElements = array())
- {
- $coords = $this->getCoordinates($elementID);
- $this->createScreenshot($identifier, $coords, $excludeElements);
-
- $compareResult = $this->compare($identifier);
-
- $deviation = round($compareResult[1] * 100, 2);
-
- $this->debug("The deviation between the images is ". $deviation . " percent");
-
- return array (
- "deviation" => $deviation,
- "deviationImage" => $compareResult[0],
- "currentImage" => $compareResult['currentImage'],
- );
- }
-
- /**
- * Initialize the module and read the config.
- * Throws a runtime exception, if the
- * reference image dir is not set in the config
- *
- * @throws \RuntimeException
- */
- private function init()
- {
- if (array_key_exists('maximumDeviation', $this->config)) {
- $this->maximumDeviation = $this->config["maximumDeviation"];
- }
-
- if (array_key_exists('saveCurrentImageIfFailure', $this->config)) {
- $this->saveCurrentImageIfFailure = (boolean) $this->config["saveCurrentImageIfFailure"];
- }
-
- if (array_key_exists('referenceImageDir', $this->config)) {
- $this->referenceImageDir = $this->config["referenceImageDir"];
- } else {
- $this->referenceImageDir = \Codeception\Configuration::dataDir() . 'VisualCeption/';
- }
-
- if (!is_dir($this->referenceImageDir)) {
- $this->debug("Creating directory: $this->referenceImageDir");
- mkdir($this->referenceImageDir, 0777, true);
- }
-
- if (array_key_exists('currentImageDir', $this->config)) {
- $this->currentImageDir = $this->config["currentImageDir"];
- }else{
- $this->currentImageDir = \Codeception\Configuration::logDir() . 'debug/tmp/';
- }
- }
-
- /**
- * Find the position and proportion of a DOM element, specified by it's ID.
- * The method inject the
- * JQuery Framework and uses the "noConflict"-mode to get the width, height and offset params.
- *
- * @param string $elementId DOM ID of the element, which should be screenshotted
- * @return array coordinates of the element
- */
- private function getCoordinates($elementId)
- {
- if (is_null($elementId)) {
- $elementId = 'body';
- }
-
- $jQueryString = file_get_contents(__DIR__ . "/jquery.js");
- $this->webDriver->executeScript($jQueryString);
- $this->webDriver->executeScript('jQuery.noConflict();');
-
- $imageCoords = array();
-
- $elementExists = (bool)$this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).length > 0;');
-
- if (!$elementExists) {
- throw new \Exception("The element you want to examine ('" . $elementId . "') was not found.");
- }
-
- $imageCoords['offset_x'] = (string)$this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).offset().left;');
- $imageCoords['offset_y'] = (string)$this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).offset().top;');
- $imageCoords['width'] = (string)$this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).width();');
- $imageCoords['height'] = (string)$this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).height();');
-
- return $imageCoords;
- }
-
- /**
- * Generates a screenshot image filename
- * it uses the testcase name and the given indentifier to generate a png image name
- *
- * @param string $identifier identifies your test object
- * @return string Name of the image file
- */
- private function getScreenshotName($identifier)
- {
- $caseName = str_replace('Cept.php', '', $this->test->getFileName());
-
- $search = array('/', '\\');
- $replace = array('.', '.');
- $caseName = str_replace($search, $replace, $caseName);
-
- return $caseName . '.' . $identifier . '.png';
- }
-
- /**
- * Returns the temporary path including the filename where a the screenshot should be saved
- * If the path doesn't exist, the method generate it itself
- *
- * @param string $identifier identifies your test object
- * @return string Path an name of the image file
- * @throws \RuntimeException if debug dir could not create
- */
- private function getScreenshotPath($identifier)
- {
- $debugDir = $this->currentImageDir;
- if (!is_dir($debugDir)) {
- $created = mkdir($debugDir, 0777, true);
- if ($created) {
- $this->debug("Creating directory: $debugDir");
- } else {
- throw new \RuntimeException("Unable to create temporary screenshot dir ($debugDir)");
- }
- }
- return $debugDir . $this->getScreenshotName($identifier);
- }
-
- /**
- * Returns the reference image path including the filename
- *
- * @param string $identifier identifies your test object
- * @return string Name of the reference image file
- */
- private function getExpectedScreenshotPath($identifier)
- {
- return $this->referenceImageDir . $this->getScreenshotName($identifier);
- }
-
- /**
- * Generate the screenshot of the dom element
- *
- * @param string $identifier identifies your test object
- * @param array $coords Coordinates where the DOM element is located
- * @param array $excludeElements List of elements, which should not appear in the screenshot
- * @return string Path of the current screenshot image
- */
- private function createScreenshot($identifier, array $coords, array $excludeElements = array())
- {
- $screenShotDir = \Codeception\Configuration::logDir() . 'debug/';
-
- if( !is_dir($screenShotDir)) {
- mkdir($screenShotDir, 0777, true);
+ throw new ImageDeviationException("The deviation of the taken screenshot is too high (" . $comparisonResult->getDeviation() . "%)",
+ $comparisonResult, $this->storageStrategy, $identifier);
}
- $screenshotPath = $screenShotDir . 'fullscreenshot.tmp.png';
- $elementPath = $this->getScreenshotPath($identifier);
-
- $this->hideElementsForScreenshot($excludeElements);
- $this->webDriver->takeScreenshot($screenshotPath);
- $this->resetHideElementsForScreenshot($excludeElements);
-
- $screenShotImage = new \Imagick();
- $screenShotImage->readImage($screenshotPath);
- $screenShotImage->cropImage($coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y']);
- $screenShotImage->writeImage($elementPath);
-
- unlink($screenshotPath);
-
- return $elementPath;
}
- /**
- * Hide the given elements with CSS visibility = hidden. Wait a second after hiding
- *
- * @param array $excludeElements Array of strings, which should be not visible
- */
- private function hideElementsForScreenshot(array $excludeElements)
+ private function getVisualChanges($identifier, $elementId, array $excludedElements)
{
- foreach ($excludeElements as $element) {
- $this->hideElement($element);
- }
- $this->webDriverModule->wait(1);
+ $expectedImage = $this->storageStrategy->getImage($identifier);
+ $currentImage = $this->getCurrentImage($excludedElements, $elementId);
+ return $this->getComparisonResult($expectedImage, $currentImage);
}
- /**
- * Reset hiding the given elements with CSS visibility = visible. Wait a second after reset hiding
- *
- * @param array $excludeElements array of strings, which should be visible again
- */
- private function resetHideElementsForScreenshot(array $excludeElements)
- {
- foreach ($excludeElements as $element) {
- $this->showElement($element);
- }
- $this->webDriverModule->wait(1);
- }
-
- /**
- * Returns the image path including the filename of a deviation image
- *
- * @param $identifier identifies your test object
- * @return string Path of the deviation image
- */
- private function getDeviationScreenshotPath ($identifier, $alternativePrefix = '')
+ private function getComparisonResult(\Imagick $expectedImage, \Imagick $currentImage)
{
- $debugDir = \Codeception\Configuration::logDir() . 'debug/';
- $prefix = ( $alternativePrefix === '') ? 'compare' : $alternativePrefix;
- return $debugDir . $prefix . $this->getScreenshotName($identifier);
- }
-
-
- /**
- * Compare two images by its identifiers.
- * If the reference image doesn't exists
- * the image is copied to the reference path.
- *
- * @param $identifier identifies your test object
- * @return array Test result of image comparison
- */
- private function compare($identifier)
- {
- $expectedImagePath = $this->getExpectedScreenshotPath($identifier);
- $currentImagePath = $this->getScreenshotPath($identifier);
-
- if (!file_exists($expectedImagePath)) {
- $this->debug("Copying image (from $currentImagePath to $expectedImagePath");
- copy($currentImagePath, $expectedImagePath);
- return array (null, 0, 'currentImage' => null);
- } else {
- return $this->compareImages($expectedImagePath, $currentImagePath);
+ try {
+ $imageCompare = new \Comparison();
+ return $imageCompare->compare($expectedImage, $currentImage);
+ } catch (\ImagickException $e) {
+ $this->debug("IMagickException! Could not compare images.\nExceptionMessage: " . $e->getMessage());
+ $this->fail($e->getMessage());
}
}
- /**
- * Compares to images by given file path
- *
- * @param $image1 Path to the exprected reference image
- * @param $image2 Path to the current image in the screenshot
- * @return array Result of the comparison
- */
- private function compareImages($image1, $image2)
+ private function getCurrentImage(array $excludedElements, $elementId)
{
- $this->debug("Trying to compare $image1 with $image2");
-
- $imagick1 = new \Imagick($image1);
- $imagick2 = new \Imagick($image2);
-
- $imagick1Size = $imagick1->getImageGeometry();
- $imagick2Size = $imagick2->getImageGeometry();
-
- $maxWidth = max($imagick1Size['width'], $imagick2Size['width']);
- $maxHeight = max($imagick1Size['height'], $imagick2Size['height']);
+ $htmlManipulator = new \Manipulation($this->webDriver);
+ $htmlManipulator->hideElements($excludedElements);
- $imagick1->extentImage($maxWidth, $maxHeight, 0, 0);
- $imagick2->extentImage($maxWidth, $maxHeight, 0, 0);
-
- try {
- $result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR);
- $result[0]->setImageFormat('png');
- $result['currentImage'] = clone $imagick2;
- $result['currentImage']->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.");
- }
- return $result;
+ $htmlScreenshot = new \Screenshot($this->webDriver);
+ return $htmlScreenshot->takeScreenshot($elementId);
}
}
\ No newline at end of file
diff --git a/module/VisualCeptionReporter.php b/module/VisualCeptionReporter.php
index 8e6dafa..c1a264d 100755
--- a/module/VisualCeptionReporter.php
+++ b/module/VisualCeptionReporter.php
@@ -38,7 +38,7 @@ private function init()
if (array_key_exists('templateFile', $this->config)) {
$this->templateFile = $this->config["templateFile"];
} else {
- $this->templateFile = __DIR__ . "/report/template.php";
+ $this->templateFile = __DIR__ . "/Report/template.php";
}
}
@@ -48,8 +48,6 @@ public function _beforeSuite()
throw new \Exception("VisualCeptionReporter uses VisualCeption. Please be sure that this module is activated.");
}
- $this->referenceImageDir = $this->getModule("VisualCeption")->getReferenceImageDir();
-
$this->debug( "VisualCeptionReporter: templateFile = " . $this->templateFile );
}
@@ -58,6 +56,7 @@ public function _afterSuite()
$failedTests = $this->failed;
$vars = $this->templateVars;
$referenceImageDir = $this->referenceImageDir;
+
$i = 0;
ob_start();
diff --git a/readme.md b/readme.md
index a4ad7ec..7f8191c 100755
--- a/readme.md
+++ b/readme.md
@@ -2,7 +2,7 @@
Visual regression tests integrated in [Codeception](http://codeception.com/).
[](https://travis-ci.org/DigitalProducts/codeception-module-visualception)
-
+
This module can be used to compare the current representation of a website element with an expeted. It was written on the shoulders of codeception and integrates in a very easy way.
**Example**
diff --git a/test/integration/tests/_bootstrap.php b/test/integration/tests/_bootstrap.php
index c2c5acc..04eaf0b 100755
--- a/test/integration/tests/_bootstrap.php
+++ b/test/integration/tests/_bootstrap.php
@@ -4,4 +4,17 @@
sleep(5);
include_once __DIR__."/../../../module/VisualCeption.php";
-include_once __DIR__."/../../../module/ImageDeviationException.php";
\ No newline at end of file
+include_once __DIR__."/../../../module/ImageDeviationException.php";
+
+include_once __DIR__."/../../../module/VisualCeptionReporter.php";
+
+include_once __DIR__."/../../../module/Storage/Factory.php";
+include_once __DIR__."/../../../module/Storage/Storage.php";
+include_once __DIR__."/../../../module/Storage/FileStorage.php";
+include_once __DIR__."/../../../module/Storage/RemoteStorage.php";
+
+include_once __DIR__."/../../../module/Html/Manipulation.php";
+include_once __DIR__."/../../../module/Html/Screenshot.php";
+
+include_once __DIR__."/../../../module/Image/Comparison.php";
+include_once __DIR__."/../../../module/Image/ComparisonResult.php";
diff --git a/test/integration/tests/acceptance.suite.yml b/test/integration/tests/acceptance.suite.yml
index 40e3830..6d5cb1d 100755
--- a/test/integration/tests/acceptance.suite.yml
+++ b/test/integration/tests/acceptance.suite.yml
@@ -14,14 +14,24 @@ modules:
- WebDriver
- WebHelper
- VisualCeption
+ - VisualCeptionReporter
config:
WebDriver:
url: http://www.thewebhatesme.com
- browser: phantomjs
- host: localhost
+ #browser: phantomjs
+ browser: firefox
+ #host: localhost
+ host: 10.100.23.11
port: 4444
capabilities:
webStorageEnabled: true
VisualCeption:
maximumDeviation: 0
- saveCurrentImageIfFailure: true
\ No newline at end of file
+ saveCurrentImageIfFailure: true
+
+ storageStrategy: RemoteStorage
+ expectedImageServer: http://wordpress.ci.guj.de/tools/visualception/image.php
+ userId: bwhBR4WBEFJHBW
+
+ VisualCeptionReporter:
+ templateFile: "/app1/ela/var/www/app/vc.digital/current/module/Report/ci_template.php"
\ No newline at end of file
diff --git a/test/integration/tests/acceptance/WriteCurrentImageCest.php b/test/integration/tests/acceptance/WriteCurrentImageCest.php
deleted file mode 100755
index bf40c05..0000000
--- a/test/integration/tests/acceptance/WriteCurrentImageCest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-amOnPage("/VisualCeption/seeVisualChanges.php");
- $I->dontSeeVisualChanges("currentImageIdentifier", "#theblock");
-
- $I->wait(2);
-
- // the test has to be called twice for comparison on the travis server
- // expect failing the test
-
- $I->amOnPage("/VisualCeption/seeVisualChanges.php");
- try
- {
- $I->dontSeeVisualChanges("currentImageIdentifier", "#theblock");
- }
- catch (ImageDeviationException $exception)
- {
- $currentImagePath = $exception->getCurrentImage();
-
- if (!is_file( $exception->getCurrentImage() )) {
- throw new \PHPUnit_Framework_ExpectationFailedException("The screenshot was not saved successfully.");
- }
- }
- }
-}
\ No newline at end of file