/**
  * @param string $prefix
  * @param RemoteWebElement $element
  *
  * @return string
  * @throws RuntimeException
  */
 protected function takeScreenshot($prefix, RemoteWebElement $element = null)
 {
     $screenshotPath = $this->getScreenshotPath($prefix);
     $this->webDriver->takeScreenshot($screenshotPath);
     if (!file_exists($screenshotPath)) {
         throw new RuntimeException('Could not save screenshot');
     }
     if ($element === null) {
         return $screenshotPath;
     }
     $elementWidth = $element->getSize()->getWidth();
     $elementHeight = $element->getSize()->getHeight();
     $elementSrcX = $element->getLocation()->getX();
     $elementSrcY = $element->getLocation()->getY();
     // Create image instances
     $src = imagecreatefrompng($screenshotPath);
     $dest = imagecreatetruecolor($elementWidth, $elementHeight);
     // Copy
     imagecopy($dest, $src, 0, 0, $elementSrcX, $elementSrcY, $elementWidth, $elementHeight);
     imagepng($dest, $screenshotPath);
     if (!file_exists($screenshotPath)) {
         throw new RuntimeException('Could not save screenshot');
     }
     return $screenshotPath;
 }
Beispiel #2
0
	/**
	 * Take screenshot. Can be used for debug purposes.
	 *
	 * @throws Exception When screenshot can't be created
	 */
	public function take_screenshot()
	{
		// Change the Path to your own settings
		$screenshot = time() . ".png";

		self::$webDriver->takeScreenshot($screenshot);
	}
Beispiel #3
0
 /**
  * Generate the screenshot of the dom element
  *
  * @param string $identifier identifies your test object
  * @param array $coords Coordinates where the DOM element is located
  * @return string Path of the current screenshot image
  * @throws \RuntimeException
  */
 private function createScreenshot($identifier, array $coords)
 {
     $screenShotDir = Configuration::logDir() . 'debug/';
     if (!is_dir($screenShotDir)) {
         mkdir($screenShotDir, 0777, true);
     }
     $screenshotPath = $screenShotDir . 'fullscreenshot.tmp.png';
     $elementPath = $this->getScreenshotPath($identifier);
     $this->remoteWebDriver->takeScreenshot($screenshotPath);
     $screenShotImage = new Imagick();
     $screenShotImage->readImage($screenshotPath);
     $screenShotImage->cropImage($coords['width'], $coords['height'], $coords['x'], $coords['y']);
     $screenShotImage->writeImage($elementPath);
     unlink($screenshotPath);
     return $elementPath;
 }
Beispiel #4
0
 public function _saveScreenshot($filename)
 {
     if ($this->webDriver !== null) {
         $this->webDriver->takeScreenshot($filename);
     } else {
         codecept_debug('WebDriver::_saveScreenshot method has been called when webDriver is not set');
         codecept_debug(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
     }
 }