From 36bc43cd2151589be50fe305a11393bddc4ae6d1 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Thu, 21 Sep 2017 13:04:39 -0500 Subject: [PATCH 1/3] MQE-376 Added selector1 and selector2 to array. --- .../FunctionalTestingFramework/Test/Objects/ActionObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index cb58c361b..3cf9a3138 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -20,7 +20,7 @@ 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'; From 5ee90706015c94874835be7711c229aa59443057 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Tue, 26 Sep 2017 15:16:50 -0500 Subject: [PATCH 2/3] MQE-353 * MQE-353 CAP changes, along with exception bugfix found in last spring demo. * MQE-353 CR Changed ternary to be included in parent if. --- .../Test/Objects/ActionObject.php | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 3cf9a3138..796224fa1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -25,8 +25,7 @@ class ActionObject 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; } @@ -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; From 4c3acb4c9114246e3a33310e16c34ae9492122d7 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 27 Sep 2017 13:10:13 -0500 Subject: [PATCH 3/3] MQE 292 (#8) * MQE-292 Renamed locator to selector where applicable (schema, objects, and handlers). Also removed locatorVariables element from schema, as it was deprecated by parameterized url/selector implementation. * MQE-292 Codesniffer fixes. --- .../Page/Handlers/SectionObjectHandler.php | 6 +++--- .../Page/Objects/ElementObject.php | 14 +++++++------- .../Page/etc/SectionObject.xsd | 11 ++--------- .../Test/Objects/ActionObject.php | 2 +- 4 files changed, 13 insertions(+), 20 deletions(-) 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 796224fa1..767012694 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -323,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):