diff --git a/src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php b/src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php index e4da7f787..65edaeab2 100644 --- a/src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php @@ -20,7 +20,7 @@ class SectionObjectHandler implements ObjectHandlerInterface const TYPE = 'section'; const SUB_TYPE = 'element'; const ELEMENT_TYPE_ATTR = 'type'; - const ELEMENT_LOCATOR_ATTR = 'locator'; + const ELEMENT_SELECTOR_ATTR = 'selector'; const ELEMENT_TIMEOUT_ATTR = 'timeout'; const ELEMENT_PARAMETERIZED = 'parameterized'; @@ -102,14 +102,14 @@ private function initSectionObjects() $elements = []; foreach ($sectionData[SectionObjectHandler::SUB_TYPE] as $elementName => $elementData) { $elementType = $elementData[SectionObjectHandler::ELEMENT_TYPE_ATTR]; - $elementLocator = $elementData[SectionObjectHandler::ELEMENT_LOCATOR_ATTR]; + $elementSelector = $elementData[SectionObjectHandler::ELEMENT_SELECTOR_ATTR]; $elementTimeout = $elementData[SectionObjectHandler::ELEMENT_TIMEOUT_ATTR] ?? null; $elementParameterized = $elementData[SectionObjectHandler::ELEMENT_PARAMETERIZED] ?? false; $elements[$elementName] = new ElementObject( $elementName, $elementType, - $elementLocator, + $elementSelector, $elementTimeout, $elementParameterized ); diff --git a/src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php b/src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php index 4d867ad08..b55911b61 100644 --- a/src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php +++ b/src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php @@ -31,7 +31,7 @@ class ElementObject * * @var string */ - private $locator; + private $selector; /** * Section element timeout @@ -51,15 +51,15 @@ class ElementObject * ElementObject constructor. * @param string $name * @param string $type - * @param string $locator + * @param string $selector * @param string $timeout * @param bool $parameterized */ - public function __construct($name, $type, $locator, $timeout, $parameterized) + public function __construct($name, $type, $selector, $timeout, $parameterized) { $this->name = $name; $this->type = $type; - $this->locator = $locator; + $this->selector = $selector; $this->timeout = $timeout; $this->parameterized = $parameterized; } @@ -85,13 +85,13 @@ public function getType() } /** - * Getter for the locator of an element + * Getter for the selector of an element * * @return string */ - public function getLocator() + public function getSelector() { - return $this->locator; + return $this->selector; } /** diff --git a/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd b/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd index d69706881..e0c421dcb 100644 --- a/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd +++ b/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd @@ -58,17 +58,10 @@ - + - Locator of the element. Use %s for placeholders for variables. - - - - - - - Optional variable names separated by "," which are used to substitute %s in locator attribute. + Selector of the element. diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index cb58c361b..767012694 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -20,13 +20,12 @@ class ActionObject { const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray"]; - const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector']; + const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector', "selector1", "selector2"]; const MERGE_ACTION_ORDER_AFTER = 'after'; const ACTION_ATTRIBUTE_URL = 'url'; const ACTION_ATTRIBUTE_SELECTOR = 'selector'; const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/'; - const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]]+}}/'; - const ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED = '/{{[\w.\[\]()\',${} ]+}}/'; + const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]()\',$ ]+}}/'; /** * The unique identifier for the action @@ -298,15 +297,7 @@ private function stripAndReturnParameters($reference) */ private function findAndReplaceReferences($objectHandler, $inputString) { - //Determine if there are Parethesis and parameters. If not, use strict regex. If so, use nested regex. - preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER, $inputString, $variableMatches); - if (empty($variableMatches[0])) { - $regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN; - } else { - $regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED; - } - preg_match_all($regex, $inputString, $matches); - + preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN, $inputString, $matches); if (empty($matches[0])) { return $inputString; } @@ -332,7 +323,7 @@ private function findAndReplaceReferences($objectHandler, $inputString) throw new TestReferenceException("Could not resolve entity reference " . $inputString); } $parameterized = $obj->getElement($objField)->isParameterized(); - $replacement = $obj->getElement($objField)->getLocator(); + $replacement = $obj->getElement($objField)->getSelector(); $this->timeout = $obj->getElement($objField)->getTimeout(); break; case (get_class($obj) == EntityDataObject::class): @@ -383,24 +374,38 @@ private function matchParameterReferences($reference, $parameters) { preg_match_all('/{{[\w.]+}}/', $reference, $varMatches); if (count($varMatches[0]) > count($parameters)) { + if (is_array($parameters)) { + $parametersGiven = implode(",", $parameters); + } elseif ($parameters == null) { + $parametersGiven = "NONE"; + } else { + $parametersGiven = $parameters; + } throw new TestReferenceException( "Parameter Resolution Failed: Not enough parameters given for reference " . - $reference . ". Parameters Given: " . implode(",", $parameters) + $reference . ". Parameters Given: " . $parametersGiven ); } elseif (count($varMatches[0]) < count($parameters)) { throw new TestReferenceException( "Parameter Resolution Failed: Too many parameters given for reference " . - $reference . ". Parameters Given: " . implode(",", $parameters) + $reference . ". Parameters Given: " . implode(", ", $parameters) ); } //Attempt to Resolve {{data}} references to actual output. + //If regex matched it means that it's either a 'StringLiteral' or $key.data$/$$key.data$$ reference. + //Else assume it's a normal {{data.key}} reference and recurse through findAndReplace $resolvedParameters = []; foreach ($parameters as $parameter) { - $resolvedParameters[] = $this->findAndReplaceReferences( - DataObjectHandler::getInstance(), - $parameter - ); + preg_match_all("/[$'][\w.$]+[$']/", $parameter, $match); + if (!empty($match[0])) { + $resolvedParameters[] = ltrim(rtrim($parameter, "'"), "'"); + } else { + $resolvedParameters[] = $this->findAndReplaceReferences( + DataObjectHandler::getInstance(), + '{{' . $parameter . '}}' + ); + } } $resolveIndex = 0;