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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.buildpath
.project
.settings/
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 16 additions & 8 deletions module/VisualCeption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <langner.nils@guj.de>
* @author Torsten Franz
* @author Sebastian Neubert
*/
class VisualCeption extends \Codeception\Module
{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <datadir>/VisualCeption/)
maximumDeviation: 5 # deviation in percent
```

Expand Down
2 changes: 2 additions & 0 deletions test/integration/tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// This is global bootstrap for autoloading

sleep(5);

include_once __DIR__."/../../../module/VisualCeption.php";
1 change: 0 additions & 1 deletion test/integration/tests/_data/dump.sql

This file was deleted.

Binary file not shown.
34 changes: 0 additions & 34 deletions test/integration/tests/_log/acceptance-2014-03-24

This file was deleted.

Binary file not shown.
3 changes: 1 addition & 2 deletions test/integration/tests/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ modules:
capabilities:
webStorageEnabled: true
VisualCeption:
maximumDeviation: 0
referenceImageDir: /tmp/deviation/
maximumDeviation: 0
4 changes: 4 additions & 0 deletions test/integration/tests/acceptance/TimeComparisonCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ public function compareTimeString (WebGuy $I, $scenario)
{
$I->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");
}
}