/**
  * Returns the name
  * @param NodeElement $slide
  * @return string
  */
 public function getNameProperty(NodeElement $slide)
 {
     $selectors = Helper::getRequiredSelectors($this, ['slideImage', 'slideLink', 'slideName']);
     $nameElement = $slide->find('css', $selectors['slideName']);
     $names = ['imageAlt' => $slide->find('css', $selectors['slideImage'])->getAttribute('alt'), 'linkTitle' => $slide->find('css', $selectors['slideLink'])->getAttribute('title'), 'name' => $nameElement->getText(), 'nameTitle' => $nameElement->getAttribute('title')];
     return Helper::getUnique($names);
 }
 /**
  * @param NodeElement $scopeBlock
  *
  * @return array
  */
 protected function getScopeData(NodeElement $scopeBlock)
 {
     $ratio = $scopeBlock ? $scopeBlock->find('css', '.literal-progress')->getHtml() : '';
     $state = $scopeBlock ? explode('-', $scopeBlock->find('css', '.progress')->getAttribute('class'))[1] : '';
     $missingValuesBlocks = $scopeBlock ? $scopeBlock->findAll('css', '.missing-attributes [data-attribute]') : [];
     $missingValues = [];
     if (!empty($missingValuesBlocks)) {
         foreach ($missingValuesBlocks as $missingValuesBlock) {
             $attributeCode = $missingValuesBlock->getAttribute('data-attribute');
             $attributeLabel = $missingValuesBlock->getHtml();
             $missingValues[$attributeCode] = $attributeLabel;
         }
     }
     return ['ratio' => $ratio, 'state' => $state, 'missing_values' => $missingValues];
 }
示例#3
0
 public static function createFromNode(NodeElement $node)
 {
     $message = $node->find('css', '.noty_text')->getHtml();
     //$x = $node->getOuterHtml();
     $class = $node->getAttribute('class');
     switch ($class) {
         case 'noty_alert':
             $type = 'alert';
             break;
         case 'noty_warning':
             $type = 'warning';
             break;
         case 'noty_error':
             $type = 'error';
             break;
         case 'noty_information':
             $type = 'information';
             break;
         case 'noty_success':
             $type = 'success';
             break;
         default:
             $type = 'default';
     }
     return new NotyMessage($node, $type, $message);
 }
 /**
  * Ensure option is selected.
  */
 public function selectable()
 {
     $this->restrictElements(['select' => []]);
     $data = [$this->value, $this->element->find('xpath', "//option[@value='{$this->value}']")->getText()];
     self::debug(['Expected: %s', 'Value: %s', 'Tag: %s'], [$this->expected, implode(' => ', $data), $this->tag]);
     $this->assert(in_array($this->expected, $data), 'selected');
 }
 /**
  * Helper function returns the data of an order position
  * @param NodeElement $position
  * @param string[] $selectors
  * @return array
  */
 private function getOrderPositionData(NodeElement $position, array $selectors)
 {
     $data = [];
     foreach ($selectors as $key => $selector) {
         $element = $position->find('css', $selector);
         $data[$key] = $element->getText();
         if ($key !== 'product') {
             $data[$key] = Helper::floatValue($data[$key]);
         }
     }
     return $data;
 }
示例#6
0
 /**
  * @param NodeElement $element
  *
  * @return NodeElement|mixed|null
  */
 protected function findCommentMessage(NodeElement $element)
 {
     return $element->find('css', 'span.message');
 }
示例#7
0
 /**
  * Detects when the field is a moodleform field type.
  *
  * Note that there are fields inside moodleforms that are not
  * moodleform element; this method can not detect this, this will
  * be managed by get_field_node_type, after failing to find the form
  * element element type.
  *
  * @param NodeElement $fieldnode
  * @return bool
  */
 protected static function is_moodleform_field(NodeElement $fieldnode)
 {
     // We already waited when getting the NodeElement and we don't want an exception if it's not part of a moodleform.
     $parentformfound = $fieldnode->find('xpath', "/ancestor::form[contains(concat(' ', normalize-space(@class), ' '), ' mform ')]");
     return $parentformfound != false;
 }
 /**
  * Returns the text preview of the blog article
  * @param NodeElement $article
  * @return null|string
  */
 public function getTextProperty(NodeElement $article)
 {
     $selector = Helper::getRequiredSelector($this, 'articleText');
     return $article->find('css', $selector)->getText();
 }
示例#9
0
 /**
  * @param NodeElement $element
  * @param string $attribute
  * @param string $value
  *
  * @return NodeElement|null
  */
 public function getParentWithAttribute($element, $attribute, $value = '')
 {
     $attribute = empty($value) ? "@{$attribute}" : "contains(@{$attribute}, '{$value}')";
     return $element->find('xpath', "/ancestor::*[{$attribute}]");
 }
 /**
  * Finds the node to use for a management listitem action and clicks it.
  *
  * @param string $listingtype Either course or category.
  * @param \Behat\Mink\Element\NodeElement $listingnode
  * @param string $action The action being taken
  * @throws Behat\Mink\Exception\ExpectationException
  */
 protected function user_clicks_on_management_listing_action($listingtype, $listingnode, $action)
 {
     $actionsnode = $listingnode->find('xpath', "//*[contains(concat(' ', normalize-space(@class), ' '), '{$listingtype}-item-actions')]");
     if (!$actionsnode) {
         throw new ExpectationException("Could not find the actions for {$listingtype}", $this->getSession());
     }
     $actionnode = $actionsnode->find('css', '.action-' . $action);
     if (!$actionnode) {
         throw new ExpectationException("Expected action was not available or not found ({$action})", $this->getSession());
     }
     if ($this->running_javascript() && !$actionnode->isVisible()) {
         $actionsnode->find('css', 'a.toggle-display')->click();
         $actionnode = $actionsnode->find('css', '.action-' . $action);
     }
     $actionnode->click();
 }
示例#11
0
 /**
  * Returns the price
  * @param NodeElement $slide
  * @return float
  */
 public function getPriceProperty(NodeElement $slide)
 {
     $selector = Helper::getRequiredSelector($this, 'slidePrice');
     preg_match('(\\d+,\\d{2})', $slide->find('css', $selector)->getHtml(), $price);
     return Helper::floatValue(current($price));
 }
示例#12
0
 /**
  * @param NodeElement $item
  *
  * @return NodeElement
  *
  * @throws ElementNotFoundException
  */
 private function getDeleteButtonForCollectionItem(NodeElement $item)
 {
     $deleteButton = $item->find('css', 'a[data-form-collection="delete"]');
     if (null === $deleteButton) {
         throw new ElementNotFoundException($this->getDriver(), 'link', 'css', 'a[data-form-collection="delete"]');
     }
     return $deleteButton;
 }
 /**
  * Returns the price
  * @param NodeElement $slide
  * @return float
  */
 public function getPriceProperty(NodeElement $slide)
 {
     $selector = Helper::getRequiredSelector($this, 'slidePrice');
     $price = $slide->find('css', $selector)->getText();
     return Helper::floatValue($price);
 }
示例#14
0
 /**
  * Default method to get a slide property
  * @param NodeElement $slide
  * @param string $property
  * @return null|string
  */
 public function getSlideProperty(NodeElement $slide, $property)
 {
     $selector = Helper::getRequiredSelector($this, 'slide' . $property);
     return $slide->find('css', $selector)->getText();
 }
示例#15
0
 /**
  * Open the filter
  *
  * @param NodeElement $filter
  *
  * @throws \InvalidArgumentException
  */
 public function openFilter(NodeElement $filter)
 {
     if ($element = $filter->find('css', 'button')) {
         $element->click();
     } else {
         throw new \InvalidArgumentException('Impossible to open filter or maybe its type is not yet implemented');
     }
 }
示例#16
0
 /**
  * Finds first element with specified selector.
  *
  * @param string       $selector Selector engine name.
  * @param string|array $locator  Selector locator.
  *
  * @return NodeElement|null
  */
 public function find($selector, $locator)
 {
     return $this->_wrappedElement->find($selector, $locator);
 }
示例#17
0
 /**
  * Return the state of a switch field
  *
  * @param NodeElement $fieldContainer
  *
  * @throws \LogicException
  *
  * @return bool
  */
 protected function isSwitchFieldChecked(NodeElement $fieldContainer)
 {
     $widget = $this->spin(function () use($fieldContainer) {
         return $fieldContainer->find('css', '.field-input .switch.has-switch');
     });
     if ($widget->find('css', '.switch-on')) {
         return true;
     }
     if ($widget->find('css', '.switch-off')) {
         return false;
     }
     throw new \LogicException(sprintf('Switch "%s" is in an undefined state', $fieldContainer->name));
 }
示例#18
0
 /**
  * @Given /^I remove (\w+) element in (collection "[^"]*")$/
  */
 public function iRemoveElementInCollection($index, NodeElement $collection)
 {
     $collection->find('xpath', sprintf('/*/*[@class = "form-group"][%d]', $index))->find('css', '.collection-remove')->click();
 }
示例#19
0
 /**
  * Returns the title-attribute of the slide
  * @param NodeElement $slide
  * @return string|null
  */
 protected function getTitleProperty(NodeElement $slide)
 {
     $selector = Helper::getRequiredSelector($this, 'slideImage');
     return $slide->find('css', $selector)->getAttribute('title');
 }
示例#20
0
 /**
  * Open the filter
  *
  * @param NodeElement $filter
  *
  * @throws \InvalidArgumentException
  */
 public function openFilter(NodeElement $filter)
 {
     $element = $this->spin(function () use($filter) {
         return $filter->find('css', 'button');
     }, 'Impossible to open filter or maybe its type is not yet implemented');
     $element->click();
 }
示例#21
0
 /**
  * Recursive method to find the field type.
  *
  * Depending on the field the felement class node is in a level or in another. We
  * look recursively for a parent node with a 'felement' class to find the field type.
  *
  * @param NodeElement $fieldnode The current node.
  * @param Session $session The behat browser session
  * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done.
  */
 protected static function get_field_node_type(NodeElement $fieldnode, Session $session)
 {
     // Special handling for availability field which requires custom JavaScript.
     if ($fieldnode->getAttribute('name') === 'availabilityconditionsjson') {
         return 'availability';
     }
     if ($fieldnode->getTagName() == 'html') {
         return false;
     }
     // If the type is explictly set on the element pointed to by the label - use it.
     if ($type = $fieldnode->getParent()->getAttribute('data-fieldtype')) {
         if ($type == 'tags') {
             return 'autocomplete';
         }
         return $type;
     }
     if (!empty($fieldnode->find('xpath', '/ancestor::*[@data-passwordunmaskid]'))) {
         return 'passwordunmask';
     }
     // We look for a parent node with 'felement' class.
     if ($class = $fieldnode->getParent()->getAttribute('class')) {
         if (strstr($class, 'felement') != false) {
             // Remove 'felement f' from class value.
             return substr($class, 10);
         }
         // Stop propagation through the DOM, if it does not have a felement is not part of a moodle form.
         if (strstr($class, 'fcontainer') != false) {
             return false;
         }
     }
     return self::get_field_node_type($fieldnode->getParent(), $session);
 }
示例#22
0
 private static function reverseLength(NodeElement $header, Header $head)
 {
     $lengthElem = $header->find('css', 'div.dataTables_length');
     if ($lengthElem) {
         $length = new Length($head->getDt());
         $selectElements = $lengthElem->findAll('css', 'select');
         /** @var NodeElement $element */
         foreach ($selectElements as $selectElement) {
             $select = new Select();
             self::reverseSelect($selectElement, $select);
             $length->setSelect($select);
         }
         $head->setLength($length);
     }
 }
示例#23
0
 /**
  * Verifies if a row as the expected columns, position of columns can be added
  * for a more accurated assertion
  *
  * @param \Behat\Mink\Element\NodeElement $row Table row node element
  * @param string[] $columns Column text to assert
  * @param string[]|int[] $columnsPositions Columns positions in int or string (number must be in string)
  *
  * @return boolean
  *
  * @throws \PHPUnit_Framework_AssertionFailedError
  */
 public function existTableRow(NodeElement $row, array $columns, array $columnsPositions = null)
 {
     // find which kind of column is in this row
     $elType = $row->find('xpath', "/th");
     $type = empty($elType) ? '/td' : '/th';
     $max = count($columns);
     for ($i = 0; $i < $max; $i++) {
         $position = "";
         if (!empty($columnsPositions[$i])) {
             $position = "[{$this->getNumberFromString($columnsPositions[$i])}]";
         }
         $el = $row->find("xpath", "{$type}{$position}");
         // check if match with expected if not return false
         if ($el === null || $columns[$i] !== $el->getText()) {
             return false;
         }
     }
     // if we're here then it means all have ran as expected
     return true;
 }