Skip to content

Commit

Permalink
Change retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Drumev committed Sep 26, 2024
1 parent 1850f19 commit 95aa119
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Codeception/Module/VisualCeption.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public function dontSeeVisualChangesForViewPort(string $identifier, string $elem
* @param $deviation
* @param $seeChanges
* @return void
* @throws \Exception
*/
private function compareVisualChanges($identifier, $elementID, $excludeElements, $deviation, $seeChanges, $fullScreenshot = true): void
{
Expand All @@ -274,13 +275,18 @@ private function compareVisualChanges($identifier, $elementID, $excludeElements,
$outOfMaxDeviation = !$seeChanges && $deviationResult["deviation"] > $maximumDeviation;

if ($outOfMaxDeviation) {
$retries = 0;
$startTime = time();
$timeout = 15;

while ($outOfMaxDeviation) {
if((time() - $startTime) > $timeout){
throw new \Exception("Screenshots comparison failed after timeout - $timeout seconds");
}

while ($retries < 5 && $outOfMaxDeviation){
$deviationResult = $this->getDeviation($identifier, $elementID, $fullScreenshot, $excludeElements);
$outOfMaxDeviation = $deviationResult["deviation"] > $maximumDeviation;
$retries++;
sleep(1);
$this->webDriver->executeScript("window.scrollTo(0, 0);");
sleep(2);
}
}

Expand Down

0 comments on commit 95aa119

Please sign in to comment.