Skip to content

Commit

Permalink
Support pixelRatio param
Browse files Browse the repository at this point in the history
  • Loading branch information
nixdrey-wb committed Sep 9, 2021
1 parent f8513c9 commit a336fcb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions module/VisualCeption.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class VisualCeption extends CodeceptionModule
protected $config = [
'maximumDeviation' => 0,
'saveCurrentImageIfFailure' => true,
'pixelRatio' => 1.0,
'referenceImageDir' => 'VisualCeption/',
'currentImageDir' => 'debug/visual/',
'report' => false,
Expand All @@ -32,6 +33,7 @@ class VisualCeption extends CodeceptionModule
];

protected $saveCurrentImageIfFailure;
protected $pixelRatio;
private $referenceImageDir;

/**
Expand Down Expand Up @@ -78,6 +80,7 @@ public function _initialize()

$this->maximumDeviation = $this->config["maximumDeviation"];
$this->saveCurrentImageIfFailure = (boolean)$this->config["saveCurrentImageIfFailure"];
$this->pixelRatio = (float)$this->config["pixelRatio"];
$this->referenceImageDir = (file_exists($this->config["referenceImageDir"]) ? "" : codecept_data_dir()) . $this->config["referenceImageDir"];

if (!is_dir($this->referenceImageDir)) {
Expand Down Expand Up @@ -196,7 +199,7 @@ public function seeVisualChanges($identifier, $elementID = null, $excludeElement
* @param string $identifier identifies your test object
* @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
* @param float $deviation
* @param float $deviation
*/
public function dontSeeVisualChanges($identifier, $elementID = null, $excludeElements = array(), $deviation = null)
{
Expand Down Expand Up @@ -432,7 +435,13 @@ private function createScreenshot($identifier, array $coords, array $excludeElem
$screenshotBinary = $this->webDriver->takeScreenshot();

$screenShotImage->readimageblob($screenshotBinary);
$screenShotImage->cropImage($coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y']);

$screenShotImage->cropImage(
$coords['width'] * $this->pixelRatio,
$coords['height'] * $this->pixelRatio,
$coords['offset_x'] * $this->pixelRatio,
$coords['offset_y'] * $this->pixelRatio
);
$screenShotImage->writeImage($elementPath);
}

Expand Down

0 comments on commit a336fcb

Please sign in to comment.