Skip to content

Commit 73ddf20

Browse files
Nils LangnerNils Langner
authored andcommitted
Added vc reporter
1 parent c0f3383 commit 73ddf20

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

module/VisualCeptionReporter.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: langn
5+
* Date: 02.10.14
6+
* Time: 14:21
7+
*
8+
* /citools/tools/common/php/5.5.9/bin/php codecept.phar
9+
*
10+
* @todo config logfile
11+
*
12+
*/
13+
14+
namespace Codeception\Module;
15+
16+
class VisualCeptionReporter extends \Codeception\Module
17+
{
18+
private $failed = array();
19+
private $logFile;
20+
private $templateVars = array();
21+
private $templateFile;
22+
23+
private $referenceImageDir;
24+
25+
public function __construct($config)
26+
{
27+
$result = parent::__construct($config);
28+
$this->init();
29+
return $result;
30+
}
31+
32+
private function init()
33+
{
34+
$this->logFile = \Codeception\Configuration::logDir() . 'vcresult.html';
35+
36+
if (array_key_exists('templateVars', $this->config)) {
37+
$this->templateVars = $this->config["templateVars"];
38+
}
39+
40+
if (array_key_exists('templateFile', $this->config)) {
41+
$this->templateFile = $this->config["templateFile"];
42+
} else {
43+
$this->templateFile = __DIR__ . "/report/template.php";
44+
}
45+
46+
47+
}
48+
49+
public function _beforeSuite()
50+
{
51+
if (!$this->hasModule("VisualCeption")) {
52+
throw new \Exception("VisualCeptionReporter uses VisualCeption. Please be sure that this module is activated.");
53+
}
54+
55+
$this->referenceImageDir = $this->getModule("VisualCeption")->getReferenceImageDir();
56+
}
57+
58+
public function _afterSuite()
59+
{
60+
$failedTests = $this->failed;
61+
$vars = $this->templateVars;
62+
$referenceImageDir = $this->referenceImageDir;
63+
$i = 0;
64+
65+
ob_start();
66+
include_once $this->templateFile;
67+
$reportContent = ob_get_contents();
68+
ob_clean();
69+
70+
file_put_contents($this->logFile, $reportContent);
71+
}
72+
73+
public function _failed(\Codeception\TestCase $test, $fail)
74+
{
75+
if ($fail instanceof ImageDeviationException) {
76+
$this->failed[] = $fail;
77+
}
78+
}
79+
}

module/report/template.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>VisualCeption Report</title>
5+
</head>
6+
<body>
7+
8+
<img src="http://www.thewebhatesme.com/wp-content/uploads/visualception.png" />
9+
10+
<?php foreach ($failedTests as $failedTest): ?>
11+
12+
<div class="deviationimage">
13+
Deviation Image <br />
14+
<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents($failedTest->getDeviationImage())); ?>' />
15+
</div>
16+
17+
<div class="expectedimage">
18+
Expected Image <br />
19+
<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents($failedTest->getExpectedImage())); ?>' />
20+
</div>
21+
22+
<div class="currentimage">
23+
Current Image <br />
24+
<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents($failedTest->getCurrentImage())); ?>' />
25+
</div>
26+
27+
28+
<?php endforeach; ?>
29+
30+
</body>
31+
</html>

0 commit comments

Comments
 (0)