Posts

Showing posts with the label behat

Modify Php function to crop image border by X pixels

Modify Php function to crop image border by X pixels I have this PHP function that I use on Behat automation which takes a screenshot of an element of the page, cropping the image: protected function takeElementScreenshot($filename, $folder, $selector) { $element = $this->findElement($selector); $driver = $this->getSession()->getDriver(); $this->iScrollToTheElement('top', $selector); $previousWindowHeight = $driver->evaluateScript("window.outerHeight"); $previousViewportHeight = $driver->evaluateScript("window.innerHeight"); $domElement = "document.evaluate("$selector", document, null," . "XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue"; $elementRect = $driver->evaluateScript("$domElement.getBoundingClientRect()"); if ($previousViewportHeight < $elementRect["height"]) { $windowWidth = $driver->evaluateScript("windo...