diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..baf6b9d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.buildpath +.project +.settings/ diff --git a/.travis.yml b/.travis.yml index f0044d3..7a080b9 100755 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,9 @@ php: before_script: - printf "\n" | pecl install imagick - wget http://selenium.googlecode.com/files/selenium-server-standalone-2.35.0.jar - - java -jar selenium-server-standalone-2.35.0.jar -port 4444 & + - java -jar selenium-server-standalone-2.35.0.jar -port 4444 >/dev/null 2>&1 & - cd test/integration/ - + - mkdir tests/_log -script: php -d include_path="." codecept.phar run + +script: php codecept.phar run -d \ No newline at end of file diff --git a/module/VisualCeption.php b/module/VisualCeption.php index ff8779e..149763d 100755 --- a/module/VisualCeption.php +++ b/module/VisualCeption.php @@ -7,6 +7,10 @@ * @copyright Copyright (c) 2014 G+J Digital Products GmbH * @license MIT license, http://www.opensource.org/licenses/mit-license.php * @package Codeception\Module + * + * @author Nils Langner + * @author Torsten Franz + * @author Sebastian Neubert */ class VisualCeption extends \Codeception\Module { @@ -53,11 +57,12 @@ private function init () if (array_key_exists('referenceImageDir', $this->config)) { $this->referenceImageDir = $this->config["referenceImageDir"]; } else { - throw new \RuntimeException("Reference image dir was not set, but is mandatory."); + $this->referenceImageDir = \Codeception\Configuration::dataDir() . 'VisualCeption/'; } if (! is_dir($this->referenceImageDir)) { - mkdir($this->referenceImageDir, 0666); + $this->debug("Creating directory: $this->referenceImageDir"); + mkdir($this->referenceImageDir, 0777, true); } } @@ -112,7 +117,13 @@ private function getScreenshotPath ($identifier) { $debugDir = \Codeception\Configuration::logDir() . 'debug/tmp/'; if (! is_dir($debugDir)) { - mkdir($debugDir, 0666); + $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); } @@ -160,7 +171,7 @@ private function createScreenshot ($identifier, array $coords) * and their element ID * * @param string $identifier identifies your test object - * @param null $elementID DOM ID of the element, which should be screenshotted + * @param string $elementID DOM ID of the element, which should be screenshotted */ public function compareScreenshot ($identifier, $elementID = null) { @@ -171,8 +182,6 @@ public function compareScreenshot ($identifier, $elementID = null) unlink($this->getScreenshotPath($identifier)); - $this->debug($compareResult); - $deviation = round($compareResult[1] * 100, 2); if ($deviation > $this->maximumDeviation) { @@ -207,6 +216,7 @@ private function compare ($identifier) $expectedImagePath = $this->getExpectedScreenshotPath($identifier); if (! file_exists($expectedImagePath)) { + $this->debug("Copying image (from $currentImagePath to $expectedImagePath"); copy($currentImagePath, $expectedImagePath); return array (null, 0); } else { @@ -229,8 +239,6 @@ private function compareImages ($image1, $image2) $result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR); $result[0]->setImageFormat("png"); - $this->debug($result); - return $result; } } diff --git a/readme.md b/readme.md index 5d1bf4f..4de3619 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,8 @@ modules: enabled: [WebDriver, VisualCeption] VisualCeption: - referenceImageDir: /home/codeception/referenceImages/ # Path to the reference folder + referenceImageDir: /home/codeception/referenceImages/ # Path to the reference folder (optional, standard is + # /VisualCeption/) maximumDeviation: 5 # deviation in percent ``` diff --git a/test/integration/tests/_bootstrap.php b/test/integration/tests/_bootstrap.php index 90dd4ac..de650d0 100755 --- a/test/integration/tests/_bootstrap.php +++ b/test/integration/tests/_bootstrap.php @@ -1,4 +1,6 @@ amOnPage("/VisualCeption/time.php"); $I->compareScreenshot("the-time", "#thetime"); + + // the test has to be called twice for comparison on the travis server + $I->amOnPage("/VisualCeption/time.php"); + $I->compareScreenshot("the-time", "#thetime"); } } \ No newline at end of file