From a91d639e40e67d1a1c97e2fa0f2c81c2879dcdda Mon Sep 17 00:00:00 2001 From: Michael Yosher Date: Sun, 4 Nov 2018 11:40:35 +0200 Subject: [PATCH 1/4] Revert to workaround fix - now file as original --- eyes.selenium.php/capture/FullPageCaptureAlgorithm.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eyes.selenium.php/capture/FullPageCaptureAlgorithm.php b/eyes.selenium.php/capture/FullPageCaptureAlgorithm.php index 8201cc9..67b3064 100644 --- a/eyes.selenium.php/capture/FullPageCaptureAlgorithm.php +++ b/eyes.selenium.php/capture/FullPageCaptureAlgorithm.php @@ -160,7 +160,6 @@ public function getStitchedRegion(ImageProvider $imageProvider, $imageParts = $entirePage->getSubRegions($partImageSize); //$this->logger->verbose("imageParts: " . var_export($imageParts, true)); - $originalEntirePage = $entireSize; $this->logger->verbose("pixelRatio: $pixelRatio"); $entireSize = $entireSize->scale($pixelRatio); @@ -243,7 +242,7 @@ public function getStitchedRegion(ImageProvider $imageProvider, if ($actualImageWidth < $entireSize->getWidth() || $actualImageHeight < $entireSize->getHeight()) { $this->logger->verbose("Trimming unnecessary margins..."); - $stitchedImage = ImageUtils::getImagePart($stitchedImage, Region::CreateFromLTWH(0, 0, $originalEntirePage->getWidth(), $originalEntirePage->getHeight())); + $stitchedImage = ImageUtils::getImagePart($stitchedImage, Region::CreateFromLTWH(0, 0, $actualImageWidth, $actualImageHeight)); $this->logger->verbose("Done!"); } $debugScreenshotsProvider->save($stitchedImage, "stitched"); @@ -289,4 +288,4 @@ private function getRegionInScreenshot(Region $region, $image, $pixelRatio, return $regionInScreenshot; } -} +} \ No newline at end of file From dbdd4b6f19b25560946ed0bc8faed3fcb719d03e Mon Sep 17 00:00:00 2001 From: Michael Yosher Date: Sun, 4 Nov 2018 12:42:08 +0200 Subject: [PATCH 2/4] Fix for full screen capture - aligned classic api with fluent api --- eyes.selenium.php/Eyes.php | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/eyes.selenium.php/Eyes.php b/eyes.selenium.php/Eyes.php index b2ec3bf..41c8725 100644 --- a/eyes.selenium.php/Eyes.php +++ b/eyes.selenium.php/Eyes.php @@ -383,19 +383,8 @@ private function validateStitchMode() */ public function checkWindow($tag, $matchTimeout = null) { - if (empty($matchTimeout)) { - $matchTimeout = self::USE_DEFAULT_MATCH_TIMEOUT; - } - - if ($this->getIsDisabled()) { - $this->logger->log(sprintf("CheckWindow(%d, '%s'): Ignored", $matchTimeout, $tag)); - return; - } $this->logger->log(sprintf("CheckWindow(%d, '%s')", $matchTimeout, $tag)); - - $checkSettings = new CheckSettings(); - $checkSettings->timeout($matchTimeout); - parent::checkWindowBase(NullRegionProvider::getInstance(), $tag, false, $checkSettings); + $this->check($tag, Target::window()->timeout($matchTimeout)); } /** @@ -567,7 +556,7 @@ private function checkFrameFluent($name, ICheckSettings $checkSettings, $switche // $imageProvider = new TakesScreenshotImageProvider($this->logger, $this->driver); // $regionProvider = new FullFrameOrElementRegionProvider($this->logger, $this, $imageProvider); - $this->checkWindowBase($regionProvider, $name, false, $checkSettings); + $this->checkWindow($regionProvider, $name, false, $checkSettings); } return $switchedToFrameCount; } @@ -585,7 +574,7 @@ private function checkFullFrameOrElement($name, ICheckSettings $checkSettings) $regionProvider = new FullFrameOrElementRegionProvider($this->logger, $this, $this->imageProvider); - $this->checkWindowBase($regionProvider, $name, false, $checkSettings); + $this->checkWindow($regionProvider, $name, false, $checkSettings); $this->checkFrameOrElement = false; } @@ -640,7 +629,7 @@ private function checkElement_(WebDriverElement $targetElement, $name, ICheckSet $this->logger->verbose("Element region: $this->regionToCheck"); - $this->checkWindowBase(NullRegionProvider::getInstance(), $name, false, $checkSettings); + $this->checkWindow(NullRegionProvider::getInstance(), $name, false, $checkSettings); } finally { if ($originalOverflow != null) { $element->setOverflow($originalOverflow); @@ -675,7 +664,7 @@ private function checkRegion_(WebDriverElement $element, $name, ICheckSettings $ $regionProvider = new RegionProvider(Region::CreateFromLTWH($p->getX(), $p->getY(), $s->getWidth(), $s->getHeight())); $regionProvider->setCoordinatesType(CoordinatesType::CONTEXT_RELATIVE); - $this->checkWindowBase($regionProvider, $name, false, $checkSettings); + $this->checkWindow($regionProvider, $name, false, $checkSettings); $this->logger->verbose("Done! trying to scroll back to original position..."); } @@ -721,7 +710,7 @@ public function checkRegion($region, $matchTimeout = null, $tag = null, $stitchC $regionProvider = new RegionProvider($targetRegion); $regionProvider->setCoordinatesType(CoordinatesType::SCREENSHOT_AS_IS); //FIXME need to check - parent::checkWindowBase( + $this->checkWindow( $regionProvider, $tag, false, @@ -790,7 +779,7 @@ public function checkRegionByElement(WebDriverElement $element, $matchTimeout = $eyesElement = new EyesRemoteWebElement($this->logger, $this->driver, $element); $fullRegion = new FullRegionProvider($eyesElement); - parent::checkWindowBase( + $this->checkWindow( $fullRegion, $tag, false, @@ -943,7 +932,7 @@ protected function checkCurrentFrame($matchTimeout, $tag) $this->regionToCheck->setCoordinatesType(CoordinatesType::SCREENSHOT_AS_IS); - parent::checkWindowBase($this->regionToCheck, $tag, false, Target::window()->timeout($matchTimeout)); + $this->checkWindow($this->regionToCheck, $tag, false, Target::window()->timeout($matchTimeout)); } finally { $this->checkFrameOrElement = false; $this->regionToCheck = null; @@ -1147,7 +1136,7 @@ protected function checkElement($element, $matchTimeout = null, $tag = null) $this->regionToCheck = new RegionProvider($elementRegion); $this->regionToCheck->setCoordinatesType(CoordinatesType::CONTEXT_RELATIVE); - parent::checkWindowBase($this->regionToCheck, $tag, false, Target::window()->timeout($matchTimeout)); + $this->checkWindow($this->regionToCheck, $tag, false, Target::window()->timeout($matchTimeout)); } finally { if ($originalOverflow != null) { $eyesElement->setOverflow($originalOverflow); From 714905468dafbfac9059179d9bc1efc4e5106680 Mon Sep 17 00:00:00 2001 From: Michael Yosher Date: Sun, 4 Nov 2018 14:00:17 +0200 Subject: [PATCH 3/4] Fluent API usage on all selenium check endpoints --- eyes.selenium.php/Eyes.php | 232 ++----------------------------------- 1 file changed, 8 insertions(+), 224 deletions(-) diff --git a/eyes.selenium.php/Eyes.php b/eyes.selenium.php/Eyes.php index 41c8725..d6a044e 100644 --- a/eyes.selenium.php/Eyes.php +++ b/eyes.selenium.php/Eyes.php @@ -681,44 +681,7 @@ private function checkRegion_(WebDriverElement $element, $name, ICheckSettings $ */ public function checkRegion($region, $matchTimeout = null, $tag = null, $stitchContent = false) { - if ($this->getIsDisabled()) { - $this->logger->log("CheckRegion($region, $matchTimeout, '$tag'): Ignored"); - return; - } - - $targetRegion = null; - if ($region instanceof Region) { - $targetRegion = $region; - } else if ($region instanceof WebDriverElement) { - $this->checkRegionByElement($region, $matchTimeout, $tag, $stitchContent); - return; - } else if ($region instanceof WebDriverBy) { - $element = $this->driver->findElement($region); - $this->checkRegionByElement($element, $matchTimeout, $tag, $stitchContent); - return; - } else if (is_string($region)) { - $element = self::findElement($this->driver, $region); - $this->checkRegionByElement($element, $matchTimeout, $tag, $stitchContent); - return; - } else { - throw new \Exception("couldn't handle region of type " . get_class($region)); - } - - ArgumentGuard::notNull($targetRegion, "region"); - - $this->logger->log("CheckRegion($targetRegion, $matchTimeout, '$tag')"); - - $regionProvider = new RegionProvider($targetRegion); - $regionProvider->setCoordinatesType(CoordinatesType::SCREENSHOT_AS_IS); //FIXME need to check - $this->checkWindow( - $regionProvider, - $tag, - false, - Target::window()->timeout($matchTimeout) - ); - $this->logger->log("Done! trying to scroll back to original position..."); - $this->regionVisibilityStrategy->returnToOriginalPosition($this->positionProvider); /// ???? - $this->logger->log("Done!"); + $this->check($tag, Target::region($region)->timeout($matchTimeout)->fully($stitchContent)); } /** @@ -733,15 +696,9 @@ public function checkRegion($region, $matchTimeout = null, $tag = null, $stitchC * @throws TestFailedException * @throws \Exception */ - public function checkRegionBySelector(WebDriverBy $selector, $matchTimeout = null, $tag, $stitchContent = false) + public function checkRegionBySelector(WebDriverBy $selector, $matchTimeout = null, $tag = "", $stitchContent = false) { - if ($this->getIsDisabled()) { - $this->logger->log("checkRegionBySelector(selector, $matchTimeout, '$tag'): Ignored"); - return; - } - - $element = $this->driver->findElement($selector); - $this->checkRegionByElement($element, $matchTimeout, $tag, $stitchContent); + $this->check($tag, Target::region($selector)->timeout($matchTimeout)->fully($stitchContent)); } /** @@ -756,38 +713,9 @@ public function checkRegionBySelector(WebDriverBy $selector, $matchTimeout = nul * @throws TestFailedException * @throws \Exception */ - public function checkRegionByElement(WebDriverElement $element, $matchTimeout = -1, $tag, $stitchContent = false) + public function checkRegionByElement(WebDriverElement $element, $matchTimeout = -1, $tag = "", $stitchContent = false) { - if ($this->getIsDisabled()) { - $this->logger->log("checkRegionByElement(element, $matchTimeout, '$tag'): Ignored"); - return; - } - - ArgumentGuard::notNull($element, "element"); - - $this->logger->verbose("checkRegionByElement(element, $matchTimeout, '$tag', $stitchContent)"); - - if ($stitchContent) { - $this->checkElement($element, $matchTimeout, $tag); - return; - } - - // If needed, scroll to the top/left of the element (additional help to make sure it's visible). - $locationAsPoint = $element->getLocation(); - $this->regionVisibilityStrategy->moveToRegion($this->positionProvider, - new Location($locationAsPoint->getX(), $locationAsPoint->getY())); - - $eyesElement = new EyesRemoteWebElement($this->logger, $this->driver, $element); - $fullRegion = new FullRegionProvider($eyesElement); - $this->checkWindow( - $fullRegion, - $tag, - false, - Target::window()->timeout($matchTimeout) - ); - $this->logger->verbose("Done! trying to scroll back to original position.."); - $this->regionVisibilityStrategy->returnToOriginalPosition($this->positionProvider); - $this->logger->verbose("Done!"); + $this->check($tag, Target::region($element)->timeout($matchTimeout)->fully($stitchContent)); } /** @@ -830,36 +758,8 @@ private function findElementMixed($element) */ public function checkRegionInFrame($frame, $element, $tag = null, $stitchContent = false, $matchTimeout = null) { - if ($this->getIsDisabled()) { - $this->logger->log("checkRegionInFrame($frame, $element, $matchTimeout, '$tag', $stitchContent): Ignored"); - return; - } - if (empty($matchTimeout)) { - $matchTimeout = self::USE_DEFAULT_MATCH_TIMEOUT; - } - - $targetFrame = $this->findElementMixed($frame); - $this->logger->log("Switching to frame with name/id: '{$targetFrame->getID()}' ..."); - - $locationAsPoint = $targetFrame->getLocation(); - $this->regionVisibilityStrategy->moveToRegion($this->getPositionProvider(), new Location($locationAsPoint->getX(), $locationAsPoint->getY())); - - $this->driver->switchTo()->frame($targetFrame); - - $targetElement = $this->findElementMixed($element); - - if ($stitchContent) { - $this->checkElement($targetElement, $matchTimeout, $tag); - } else { - $this->checkRegionByElement($targetElement, $matchTimeout, $tag); - } - - $this->logger->log("Switching back to parent frame"); - $this->driver->switchTo()->parentFrame(); - - $this->regionVisibilityStrategy->returnToOriginalPosition($this->getPositionProvider()); - $this->logger->log("Done!"); + $this->check($tag, Target::frame($frame)->region($element)->timeout($matchTimeout)->fully($stitchContent)); } /** @@ -953,33 +853,7 @@ protected function checkCurrentFrame($matchTimeout, $tag) */ public function checkFrame($frameNameOrId, $matchTimeout, $tag) { - if ($this->getIsDisabled()) { - $this->logger->log("checkFrame('$frameNameOrId', $matchTimeout, '$tag'): Ignored"); - return; - } - if (empty($matchTimeout)) { - $matchTimeout = self::USE_DEFAULT_MATCH_TIMEOUT; - } - - ArgumentGuard::notNull($frameNameOrId, "frameNameOrId"); - - $this->logger->log("checkFrame('$frameNameOrId', $matchTimeout, '$tag')"); - $this->logger->log("Switching to frame with name/id: '$frameNameOrId' ..."); - - $locationAsPoint = self::findElement($this->driver, $frameNameOrId)->getLocation(); - $this->regionVisibilityStrategy->moveToRegion($this->getPositionProvider(), new Location($locationAsPoint->getX(), $locationAsPoint->getY())); - - $this->driver->switchTo()->frame($frameNameOrId); - - $this->logger->log("Done."); - $this->checkCurrentFrame($matchTimeout, $tag); - - $this->logger->log("Switching back to parent frame"); - $this->driver->switchTo()->parentFrame(); - - $this->regionVisibilityStrategy->returnToOriginalPosition($this->getPositionProvider()); - - $this->logger->log("Done!"); + $this->check($tag, Target::frame($frameNameOrId)->timeout($matchTimeout)); } /** @@ -1041,57 +915,6 @@ public static function findElement(EyesWebDriver $driver, $elementNameOrId) } */ - /** - * Switches into the given frame, takes a snapshot of the application under - * test and matches a region specified by the given selector. - * - * @param array $framePath The path to the frame to check. This is a list of - * frame names/IDs (where each frame is nested in the - * previous frame). - * @param WebDriverBy $selector A Selector specifying the region to check. - * @param int $matchTimeout The amount of time to retry matching (milliseconds). - * @param string $tag An optional tag to be associated with the snapshot. - * @param bool $stitchContent Whether or not to stitch the internal content of - * the region (i.e., perform - * {@link #checkElement(By, int, String)} on the - * region. - * @throws EyesException - * @throws TestFailedException - * @throws \Exception - * @throws \Facebook\WebDriver\Exception\NoSuchFrameException - */ - public function checkRegionInFramePath($framePath = array(), WebDriverBy $selector, - $matchTimeout = null, $tag, - $stitchContent = false) - { - if ($this->getIsDisabled()) { - $this->logger->log(sprintf("checkRegionInFrame(framePath, selector, %d, '%s'): Ignored", $matchTimeout, $tag)); - return; - } - if (empty($matchTimeout)) { - $matchTimeout = self::USE_DEFAULT_MATCH_TIMEOUT; - } - ArgumentGuard::notNull($framePath, "framePath"); - ArgumentGuard::greaterThanZero($framePath['length'], "framePath.length"); - $this->logger->log(sprintf("checkFrame(framePath, %d, '%s')", $matchTimeout, $tag)); - //$originalFrameChain = $this->driver->getFrameChain(); - // We'll switch into the PARENT frame of the frame we want to check, and call check frame. - $this->logger->log("Switching to parent frame according to frames path.."); - - $parentFramePath = $framePath; // this actually copies the array. - $lastFrame = array_pop($parentFramePath); - -// ((EyesTargetLocator)(driver.switchTo())).frames(parentFramePath); -//??????? - - $this->logger->log("Done! Calling checkRegionInFrame.."); - $this->checkRegionInFrame($lastFrame, $selector, $matchTimeout, $tag, $stitchContent); - $this->logger->log("Done! switching back to default content.."); - $this->driver->switchTo()->defaultContent(); - $this->logger->log("Done! Switching into the original frame.."); -//??????? ((EyesTargetLocator)(driver.switchTo())).frames(originalFrameChain); - $this->logger->log("Done!"); - } /** * Takes a snapshot of the application under test and matches a specific @@ -1107,46 +930,7 @@ public function checkRegionInFramePath($framePath = array(), WebDriverBy $select */ protected function checkElement($element, $matchTimeout = null, $tag = null) { - $originalOverflow = null; - - // Since the element might already have been found using EyesWebDriver. - if ($element instanceof EyesRemoteWebElement) { - $eyesElement = $element; - } else { - $eyesElement = new EyesRemoteWebElement($this->logger, $this->driver, $this->findElementMixed($element)); - } - - $originalPositionProvider = $this->getPositionProvider(); - $scrollPositionProvider = new ScrollPositionProvider($this->logger, $this->driver); - $originalScrollPosition = $scrollPositionProvider->getCurrentPosition(); - $loc = $eyesElement->getLocation(); - $scrollPositionProvider->setPosition(new Location($loc->getX(), $loc->getY())); - - try { - $this->checkFrameOrElement = true; - $this->setPositionProvider(new ElementPositionProvider($this->logger, $this->driver, $element)); - - $originalOverflow = $eyesElement->getOverflow(); - - // Set overflow to "hidden". - $eyesElement->setOverflow("hidden"); - - $elementRegion = $eyesElement->getClientAreaBounds(); - $this->logger->log("Element region: $elementRegion"); - - $this->regionToCheck = new RegionProvider($elementRegion); - $this->regionToCheck->setCoordinatesType(CoordinatesType::CONTEXT_RELATIVE); - $this->checkWindow($this->regionToCheck, $tag, false, Target::window()->timeout($matchTimeout)); - } finally { - if ($originalOverflow != null) { - $eyesElement->setOverflow($originalOverflow); - } - - $this->checkFrameOrElement = false; - $scrollPositionProvider->setPosition($originalScrollPosition); - $this->setPositionProvider($originalPositionProvider); - $this->regionToCheck = null; - } + $this->check($tag, Target::regionByWebElement($element)->timeout($matchTimeout)); } /** From bcaad87449f91dee5aad0de781bb5dc1f792ff70 Mon Sep 17 00:00:00 2001 From: Michael Yosher Date: Sun, 4 Nov 2018 14:09:14 +0200 Subject: [PATCH 4/4] revert wrongly changed function --- eyes.selenium.php/Eyes.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eyes.selenium.php/Eyes.php b/eyes.selenium.php/Eyes.php index d6a044e..9993a22 100644 --- a/eyes.selenium.php/Eyes.php +++ b/eyes.selenium.php/Eyes.php @@ -556,7 +556,7 @@ private function checkFrameFluent($name, ICheckSettings $checkSettings, $switche // $imageProvider = new TakesScreenshotImageProvider($this->logger, $this->driver); // $regionProvider = new FullFrameOrElementRegionProvider($this->logger, $this, $imageProvider); - $this->checkWindow($regionProvider, $name, false, $checkSettings); + parent::checkWindowBase($regionProvider, $name, false, $checkSettings); } return $switchedToFrameCount; } @@ -574,7 +574,7 @@ private function checkFullFrameOrElement($name, ICheckSettings $checkSettings) $regionProvider = new FullFrameOrElementRegionProvider($this->logger, $this, $this->imageProvider); - $this->checkWindow($regionProvider, $name, false, $checkSettings); + parent::checkWindowBase($regionProvider, $name, false, $checkSettings); $this->checkFrameOrElement = false; } @@ -629,7 +629,7 @@ private function checkElement_(WebDriverElement $targetElement, $name, ICheckSet $this->logger->verbose("Element region: $this->regionToCheck"); - $this->checkWindow(NullRegionProvider::getInstance(), $name, false, $checkSettings); + parent::checkWindowBase(NullRegionProvider::getInstance(), $name, false, $checkSettings); } finally { if ($originalOverflow != null) { $element->setOverflow($originalOverflow); @@ -664,7 +664,7 @@ private function checkRegion_(WebDriverElement $element, $name, ICheckSettings $ $regionProvider = new RegionProvider(Region::CreateFromLTWH($p->getX(), $p->getY(), $s->getWidth(), $s->getHeight())); $regionProvider->setCoordinatesType(CoordinatesType::CONTEXT_RELATIVE); - $this->checkWindow($regionProvider, $name, false, $checkSettings); + parent::checkWindowBase($regionProvider, $name, false, $checkSettings); $this->logger->verbose("Done! trying to scroll back to original position..."); }