From a336fcbd0343a14512d10cb8aeeb17788553323b Mon Sep 17 00:00:00 2001 From: Andrei Usov Date: Thu, 9 Sep 2021 15:57:51 +0300 Subject: [PATCH] Support pixelRatio param --- module/VisualCeption.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/module/VisualCeption.php b/module/VisualCeption.php index 37ab601..186f79a 100755 --- a/module/VisualCeption.php +++ b/module/VisualCeption.php @@ -24,6 +24,7 @@ class VisualCeption extends CodeceptionModule protected $config = [ 'maximumDeviation' => 0, 'saveCurrentImageIfFailure' => true, + 'pixelRatio' => 1.0, 'referenceImageDir' => 'VisualCeption/', 'currentImageDir' => 'debug/visual/', 'report' => false, @@ -32,6 +33,7 @@ class VisualCeption extends CodeceptionModule ]; protected $saveCurrentImageIfFailure; + protected $pixelRatio; private $referenceImageDir; /** @@ -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)) { @@ -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) { @@ -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); }