/**
  * @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;
 }
Пример #2
0
 /**
  * @param RemoteWebElement $fieldContext
  * @param array $testValues An array of arrays that contains the values to validate.
  *  * First value is the input value
  *  * second value is the value that is expected after the validation
  *  * optional third value is the "internal" value like required for date fields (value is internally
  *      represented by a timestamp). If this value is not defined the second value will be used.
  *  Example for field with alpha validation: [['foo', 'foo'], ['bar1'], ['bar']]
  *  Example for field with date validation: [['29-01-2016', '29-01-2016', '1454025600']]
  */
 public function fillSeeDeleteInputField(RemoteWebElement $fieldContext, array $testValues)
 {
     $I = $this->tester;
     $I->wantTo('Fill field, check the fieldvalue after evaluation and delete the value.');
     $inputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
     $internalInputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]'));
     foreach ($testValues as $comment => $testValue) {
         if (!empty($comment)) {
             $I->comment($comment);
         }
         $I->comment('Fill the field and switch focus to trigger validation.');
         $I->fillField($inputField, $testValue[0]);
         // change the focus to trigger validation
         $fieldContext->sendKeys("\n");
         $I->comment('Test value of "visible" field');
         $I->canSeeInField($inputField, $testValue[1]);
         $I->comment('Test value of the internal field');
         $I->canSeeInField($internalInputField, isset($testValue[2]) ? $testValue[2] : $testValue[1]);
     }
     $inputField->findElement(\WebDriverBy::xpath('parent::*/button[@class="close"]'))->click();
     // change the context from the field
     $fieldContext->sendKeys("\n");
     $I->canSeeInField($inputField, '');
     $I->canSeeInField($internalInputField, '');
 }
Пример #3
0
 /**
  * Move the web drivers mouse to the expected element.
  *
  * @param RemoteWebElement $element Element to hover.
  * @param bool|null        $click   (Optional) Click at the hovered element after moving.
  *
  * @return MouseTrait|$this Same instance for chained method calls.
  */
 public function moveMouseToElement(RemoteWebElement $element, $click = null)
 {
     $mouse = $this->getWebDriver()->getMouse()->mouseMove($element->getCoordinates());
     $click ? $mouse->click() : null;
     return $this;
 }
 /**
  * Create screenshot for an element
  *
  * @param string $referenceImageName
  * @param RemoteWebElement $element
  * @return \Imagick
  */
 protected function _createScreenshot($referenceImageName, RemoteWebElement $element)
 {
     // Try scrolling the element into the view port
     $element->getLocationOnScreenOnceScrolledIntoView();
     $tempImagePath = $this->moduleFileSystemUtil->getTempImagePath($referenceImageName);
     $this->webDriver->webDriver->takeScreenshot($tempImagePath);
     $image = new \Imagick($tempImagePath);
     $image->cropImage($element->getSize()->getWidth(), $element->getSize()->getHeight(), $element->getCoordinates()->onPage()->getX(), $element->getCoordinates()->onPage()->getY());
     $image->setImageFormat('png');
     $image->writeImage($tempImagePath);
     return $image;
 }