/** * Recursive walks tree * * @param ElementInterface $node * @param string $parentCssClass * @return array */ protected function _getNodeContent(ElementInterface $node, $parentCssClass) { $counter = 1; $nextNodeSelector = $parentCssClass . " > " . $this->nodeSelector . ":nth-of-type({$counter})"; $nodeArray = []; //Get list of all children nodes to work with $newNode = $node->find($nextNodeSelector); while ($newNode->isVisible()) { $nextCheckedNodeSelector = $parentCssClass . " > " . $this->checkedNodeSelector . ":nth-of-type({$counter})"; $nodesNames = $newNode->find($this->nodeName); $text = ltrim($nodesNames->getText()); $childNodeSelector = $nextNodeSelector . $this->nodeCssClass; $nodesContents = $newNode->find($childNodeSelector); $subNodes = null; if ($nodesContents->isVisible()) { $subNodes = $this->_getNodeContent($nodesContents, $childNodeSelector); } $nodeArray[] = ['name' => $text, 'isChecked' => $node->find($nextCheckedNodeSelector)->isVisible() ? true : false, 'element' => $newNode, 'subnodes' => $subNodes]; ++$counter; $nextNodeSelector = $parentCssClass . " > " . $this->nodeSelector . ":nth-of-type({$counter})"; $newNode = $node->find($nextNodeSelector); } return $nodeArray; }
/** * Get child optgroup * * @param string $value * @param ElementInterface $context * @return ElementInterface * @throws \Exception */ protected function getChildOptgroup($value, ElementInterface $context) { $childOptgroup = null; $count = 1; while (!$childOptgroup) { $optgroup = $context->find(sprintf($this->nextOptgroup, $count), Locator::SELECTOR_XPATH); if (!$optgroup->isVisible()) { throw new \Exception("Can't find child group \"{$value}\""); } $childOptgroup = $context->find(sprintf($this->childOptgroup, $count, $value), Locator::SELECTOR_XPATH); if (!$childOptgroup->isVisible()) { $childOptgroup = null; } ++$count; } return $childOptgroup; }
/** * Waiter for load children. * * @param ElementInterface $element * @return void */ protected function waitLoadChildren(ElementInterface $element) { $selector = $this->childLoader; $this->waitUntil(function () use($element, $selector) { return $element->find($selector)->isVisible() ? true : null; }); }
/** * Get bundle options block. * * @param int $rowNumber * @param ElementInterface $element * @return Option */ private function getBundleOptionBlock($rowNumber, ElementInterface $element) { return $this->blockFactory->create('Magento\\Bundle\\Test\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Section\\Bundle\\Option', ['element' => $element->find(sprintf($this->bundleOptionRow, $rowNumber), Locator::SELECTOR_XPATH)]); }
/** * Recursive walks tree * * @param ElementInterface $node * @param string $parentCssClass * @return array */ protected function getNodeContent(ElementInterface $node, $parentCssClass) { $nodeArray = []; $nodeList = []; $counter = 1; $newNode = $node->find($parentCssClass . ' > ' . $this->nodeSelector . ':nth-of-type(' . $counter . ')'); //Get list of all children nodes to work with while ($newNode->isVisible()) { $nodeList[] = $newNode; ++$counter; $newNode = $node->find($parentCssClass . ' > ' . $this->nodeSelector . ':nth-of-type(' . $counter . ')'); } //Write to array values of current node foreach ($nodeList as $currentNode) { /** @var Element $currentNode */ $nodesNames = $currentNode->find($this->nodeName); $nodesContents = $currentNode->find($this->nodeCssClass); $text = ltrim($nodesNames->getText()); $nodeArray[] = ['name' => $text, 'element' => $currentNode, 'subnodes' => $nodesContents->isVisible() ? $this->getNodeContent($nodesContents, $this->nodeCssClass) : null]; } return $nodeArray; }
/** * Find next param of condition for fill. * * @param ElementInterface $context * @return ElementInterface * @throws \Exception */ protected function findNextParam(ElementInterface $context) { do { if (!isset($this->mapParams[$this->findKeyParam])) { throw new \Exception("Empty map of params"); } $param = $this->mapParams[$this->findKeyParam]; $element = $context->find(sprintf($this->param, strlen($param), $param), Locator::SELECTOR_XPATH); $this->findKeyParam += 1; } while (!$element->isVisible()); return $element; }
/** * Assign product to variation matrix * * @param ElementInterface $variationRow * @param string $productSku * @return void */ protected function assignProduct(ElementInterface $variationRow, $productSku) { $variationRow->find($this->actionMenu)->hover(); $variationRow->find($this->actionMenu)->click(); $variationRow->find($this->chooseProduct)->click(); $this->getTemplateBlock()->waitLoader(); $this->getAssociatedProductGrid()->searchAndSelect(['sku' => $productSku]); }
/** * Get rating value. * * @param ElementInterface $itemRating * @return string */ protected function getRatingValue(ElementInterface $itemRating) { $ratingValue = $itemRating->find($this->ratingValue)->getAttribute('style'); preg_match('`(\\d+)%`', $ratingValue, $matches); return isset($matches[1]) ? $matches[1] / 20 : null; }
/** * Get option type data. * * @param array $options * @param string $type * @param ElementInterface $element * @return array */ private function getOptionTypeData(array $options, $type, ElementInterface $element) { $formDataItem = []; /** @var AbstractOptions $optionsForm */ $optionsForm = $this->blockFactory->create(__NAMESPACE__ . '\\Options\\Type\\' . $this->optionNameConvert($type), ['element' => $element]); $context = $element->find($this->addValue)->isVisible() ? $this->dynamicDataRow : $this->staticDataRow; foreach ($options as $key => $option) { if (isset($option['sort_order'])) { $currentSortOrder = (int) $option['sort_order']; unset($option['sort_order']); } $formDataItem['options'][$key] = $optionsForm->getDataOptions($option, $element->find(sprintf($context, $key + 1))); if (isset($currentSortOrder)) { $formDataItem['options'][$key]['sort_order'] = $key; } } return $formDataItem; }