Example #1
0
 /**
  * @param ElementInterface $element
  * @param string[] $fields
  *
  * @return ElementInterface|null
  */
 private function getFormWithFields(ElementInterface $element, array $fields)
 {
     /** @var NodeElement[] $forms */
     $forms = $element->findAll('css', 'form');
     foreach ($forms as $form) {
         $found = true;
         foreach ($fields as $field) {
             if (null === $form->findField($field)) {
                 $found = false;
             }
         }
         if ($found) {
             return $form;
         }
     }
     return null;
 }
Example #2
0
 /**
  * Extracts and return the label NodeElement, identified by $field content and $element
  *
  * @param string           $field
  * @param ElementInterface $element
  *
  * @return \Behat\Mink\Element\NodeElement
  */
 protected function extractLabelElement($field, ElementInterface $element = null)
 {
     $subLabelContent = null;
     $channel = null;
     $labelContent = $field;
     if (false !== strpbrk($field, '€$')) {
         if (false !== strpos($field, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $field);
         }
     }
     if ($element) {
         $label = $this->spin(function () use($element, $labelContent) {
             return $element->find('css', sprintf('label:contains("%s")', $labelContent));
         }, sprintf('Cannot find "%s" label', $labelContent));
     } else {
         $labeParts = explode(' ', $labelContent);
         $channel = in_array(reset($labeParts), ['mobile', 'ecommerce', 'print', 'tablet']) ? reset($labeParts) : null;
         if (null !== $channel) {
             $labelContent = substr($labelContent, strlen($channel . ' '));
         }
         $label = $this->spin(function () use($labelContent) {
             return $this->find('css', sprintf('label:contains("%s")', $labelContent));
         }, sprintf('Cannot find "%s" label', $labelContent));
     }
     if (!$label) {
         $label = new \stdClass();
     }
     $label->channel = $channel;
     $label->labelContent = $labelContent;
     $label->subLabelContent = $subLabelContent;
     return $label;
 }
Example #3
0
 /**
  * Drags current node onto other node.
  *
  * @param   ElementInterface    $destination    other node
  */
 public function dragTo(ElementInterface $destination)
 {
     $this->getSession()->getDriver()->dragTo($this->getXpath(), $destination->getXpath());
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 protected function extractLabelElement($field, ElementInterface $element = null)
 {
     $subLabelContent = null;
     $labelContent = $field;
     if (strstr($field, 'USD') || strstr($field, 'EUR')) {
         if (false !== strpos($field, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $field);
         }
     }
     if (null !== $element) {
         $label = $this->spin(function () use($element, $labelContent) {
             return $element->find('css', sprintf('label:contains("%s")', $labelContent));
         }, sprintf('Unable to find label %s in element : %s', $labelContent, $element->getHtml()));
     } else {
         $label = $this->spin(function () use($labelContent) {
             return $this->find('css', sprintf('label:contains("%s")', $labelContent));
         }, sprintf('Unable to find label %s', $labelContent));
     }
     $label->labelContent = $labelContent;
     $label->subLabelContent = $subLabelContent;
     return $label;
 }