Skip to content

Commit

Permalink
Fix full-screen screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
znchelyazkov committed Apr 5, 2023
1 parent 92ca816 commit e2b3574
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions module/VisualCeption.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VisualCeption extends CodeceptionModule implements MultiSession
'module' => 'WebDriver',
'fullScreenShot' => false
];

protected $saveCurrentImageIfFailure;
private $referenceImageDir;

Expand Down Expand Up @@ -161,7 +161,7 @@ protected function getBrowserModule() {

return null;
}

/**
* Get value of the private property $referenceImageDir
*
Expand All @@ -179,7 +179,7 @@ public function getReferenceImageDir()
* @param string $identifier Identifies your test object
* @param string $elementID DOM ID of the element, which should be screenshotted
* @param string|array $excludeElements Element name or array of Element names, which should not appear in the screenshot
* @param float $deviation
* @param float $deviation
*/
public function seeVisualChanges($identifier, $elementID = null, $excludeElements = array(), $deviation = null)
{
Expand All @@ -197,7 +197,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 @@ -416,17 +416,23 @@ private function createScreenshot($identifier, array $coords, array $excludeElem
list($viewportHeight, $devicePixelRatio) = $this->webDriver->executeScript("return [window.innerHeight, window.devicePixelRatio]");

$itr = $height / $viewportHeight;
$isViewPortHeightBiggerThanPageHeight = $height > $viewportHeight;

for ($i = 0; $i < intval($itr); $i++) {
$screenshotBinary = $this->webDriver->takeScreenshot();
$screenShotImage->readimageblob($screenshotBinary);
$this->webDriver->executeScript("window.scrollBy(0, {$viewportHeight});");
if ($isViewPortHeightBiggerThanPageHeight) {
for ($i = 0; $i < intval($itr); $i++) {
$screenshotBinary = $this->webDriver->takeScreenshot();
$screenShotImage->readimageblob($screenshotBinary);
$this->webDriver->executeScript("window.scrollBy(0, {$viewportHeight});");
}
}

$screenshotBinary = $this->webDriver->takeScreenshot();
$screenShotImage->readimageblob($screenshotBinary);
$heightOffset = $viewportHeight - ($height - (intval($itr) * $viewportHeight));
$screenShotImage->cropImage(0, 0, 0, $heightOffset * $devicePixelRatio);

if ($isViewPortHeightBiggerThanPageHeight) {
$screenShotImage->cropImage(0, 0, 0, $heightOffset * $devicePixelRatio);
}

$screenShotImage->resetIterator();
$fullShot = $screenShotImage->appendImages(true);
Expand Down Expand Up @@ -605,4 +611,4 @@ public function _closeSession($session = null)
{
// this method will never be needed
}
}
}

0 comments on commit e2b3574

Please sign in to comment.