Created
April 23, 2014 09:22
-
-
Save amenk/11208415 to your computer and use it in GitHub Desktop.
Take a screenshot of a specific part (CSS selector) in Behat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Then /^take a screenshot of "([^"]*)" and save "([^"]*)"$/ | |
*/ | |
public function takeAScreenshotOfAndSave($selector, $filename) | |
{ | |
$this->saveScreenshot($filename, '/tmp'); | |
$pos = $this->getSession()->evaluateScript('$$("' . $selector . '").first().getBoundingClientRect();'); | |
$dst_image = imagecreatetruecolor(round($pos['width']), round($pos['height'])); | |
$src_image = imagecreatefrompng("/tmp/" . $filename); | |
imagecopyresampled($dst_image, $src_image, | |
0, 0, | |
round($pos['left']), round($pos['top']), round($pos['width']), round($pos['height']), | |
round($pos['width']), round($pos['height'])); | |
imagepng($dst_image, "/tmp/" . $filename); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment