Skip to content

Commit c4ba775

Browse files
authored
Merge pull request #4 from magento-pangolin/tmp
[Pangolin] Deliver changes to mainline framework repo - MQE-376 [Framework] Resolve selector1 and selector2 replacements in ActionObject - MQE-353 [Generator] Remove double curly braces from parameterized data references. - MQE-292 Use "selector" name consistently instead of "locator"
2 parents dfde8ba + b111c4d commit c4ba775

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SectionObjectHandler implements ObjectHandlerInterface
2020
const TYPE = 'section';
2121
const SUB_TYPE = 'element';
2222
const ELEMENT_TYPE_ATTR = 'type';
23-
const ELEMENT_LOCATOR_ATTR = 'locator';
23+
const ELEMENT_SELECTOR_ATTR = 'selector';
2424
const ELEMENT_TIMEOUT_ATTR = 'timeout';
2525
const ELEMENT_PARAMETERIZED = 'parameterized';
2626

@@ -102,14 +102,14 @@ private function initSectionObjects()
102102
$elements = [];
103103
foreach ($sectionData[SectionObjectHandler::SUB_TYPE] as $elementName => $elementData) {
104104
$elementType = $elementData[SectionObjectHandler::ELEMENT_TYPE_ATTR];
105-
$elementLocator = $elementData[SectionObjectHandler::ELEMENT_LOCATOR_ATTR];
105+
$elementSelector = $elementData[SectionObjectHandler::ELEMENT_SELECTOR_ATTR];
106106
$elementTimeout = $elementData[SectionObjectHandler::ELEMENT_TIMEOUT_ATTR] ?? null;
107107
$elementParameterized = $elementData[SectionObjectHandler::ELEMENT_PARAMETERIZED] ?? false;
108108

109109
$elements[$elementName] = new ElementObject(
110110
$elementName,
111111
$elementType,
112-
$elementLocator,
112+
$elementSelector,
113113
$elementTimeout,
114114
$elementParameterized
115115
);

src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ElementObject
3131
*
3232
* @var string
3333
*/
34-
private $locator;
34+
private $selector;
3535

3636
/**
3737
* Section element timeout
@@ -51,15 +51,15 @@ class ElementObject
5151
* ElementObject constructor.
5252
* @param string $name
5353
* @param string $type
54-
* @param string $locator
54+
* @param string $selector
5555
* @param string $timeout
5656
* @param bool $parameterized
5757
*/
58-
public function __construct($name, $type, $locator, $timeout, $parameterized)
58+
public function __construct($name, $type, $selector, $timeout, $parameterized)
5959
{
6060
$this->name = $name;
6161
$this->type = $type;
62-
$this->locator = $locator;
62+
$this->selector = $selector;
6363
$this->timeout = $timeout;
6464
$this->parameterized = $parameterized;
6565
}
@@ -85,13 +85,13 @@ public function getType()
8585
}
8686

8787
/**
88-
* Getter for the locator of an element
88+
* Getter for the selector of an element
8989
*
9090
* @return string
9191
*/
92-
public function getLocator()
92+
public function getSelector()
9393
{
94-
return $this->locator;
94+
return $this->selector;
9595
}
9696

9797
/**

src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,10 @@
5858
</xs:documentation>
5959
</xs:annotation>
6060
</xs:attribute>
61-
<xs:attribute type="notEmptyType" name="locator" use="required">
61+
<xs:attribute type="notEmptyType" name="selector" use="required">
6262
<xs:annotation>
6363
<xs:documentation>
64-
Locator of the element. Use %s for placeholders for variables.
65-
</xs:documentation>
66-
</xs:annotation>
67-
</xs:attribute>
68-
<xs:attribute type="notEmptyType" name="locatorVariables" use="optional">
69-
<xs:annotation>
70-
<xs:documentation>
71-
Optional variable names separated by "," which are used to substitute %s in locator attribute.
64+
Selector of the element.
7265
</xs:documentation>
7366
</xs:annotation>
7467
</xs:attribute>

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
class ActionObject
2121
{
2222
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray"];
23-
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector'];
23+
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector', "selector1", "selector2"];
2424
const MERGE_ACTION_ORDER_AFTER = 'after';
2525
const ACTION_ATTRIBUTE_URL = 'url';
2626
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
2727
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
28-
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]]+}}/';
29-
const ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED = '/{{[\w.\[\]()\',${} ]+}}/';
28+
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]()\',$ ]+}}/';
3029

3130
/**
3231
* The unique identifier for the action
@@ -298,15 +297,7 @@ private function stripAndReturnParameters($reference)
298297
*/
299298
private function findAndReplaceReferences($objectHandler, $inputString)
300299
{
301-
//Determine if there are Parethesis and parameters. If not, use strict regex. If so, use nested regex.
302-
preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER, $inputString, $variableMatches);
303-
if (empty($variableMatches[0])) {
304-
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
305-
} else {
306-
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED;
307-
}
308-
preg_match_all($regex, $inputString, $matches);
309-
300+
preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN, $inputString, $matches);
310301
if (empty($matches[0])) {
311302
return $inputString;
312303
}
@@ -332,7 +323,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
332323
throw new TestReferenceException("Could not resolve entity reference " . $inputString);
333324
}
334325
$parameterized = $obj->getElement($objField)->isParameterized();
335-
$replacement = $obj->getElement($objField)->getLocator();
326+
$replacement = $obj->getElement($objField)->getSelector();
336327
$this->timeout = $obj->getElement($objField)->getTimeout();
337328
break;
338329
case (get_class($obj) == EntityDataObject::class):
@@ -383,24 +374,38 @@ private function matchParameterReferences($reference, $parameters)
383374
{
384375
preg_match_all('/{{[\w.]+}}/', $reference, $varMatches);
385376
if (count($varMatches[0]) > count($parameters)) {
377+
if (is_array($parameters)) {
378+
$parametersGiven = implode(",", $parameters);
379+
} elseif ($parameters == null) {
380+
$parametersGiven = "NONE";
381+
} else {
382+
$parametersGiven = $parameters;
383+
}
386384
throw new TestReferenceException(
387385
"Parameter Resolution Failed: Not enough parameters given for reference " .
388-
$reference . ". Parameters Given: " . implode(",", $parameters)
386+
$reference . ". Parameters Given: " . $parametersGiven
389387
);
390388
} elseif (count($varMatches[0]) < count($parameters)) {
391389
throw new TestReferenceException(
392390
"Parameter Resolution Failed: Too many parameters given for reference " .
393-
$reference . ". Parameters Given: " . implode(",", $parameters)
391+
$reference . ". Parameters Given: " . implode(", ", $parameters)
394392
);
395393
}
396394

397395
//Attempt to Resolve {{data}} references to actual output.
396+
//If regex matched it means that it's either a 'StringLiteral' or $key.data$/$$key.data$$ reference.
397+
//Else assume it's a normal {{data.key}} reference and recurse through findAndReplace
398398
$resolvedParameters = [];
399399
foreach ($parameters as $parameter) {
400-
$resolvedParameters[] = $this->findAndReplaceReferences(
401-
DataObjectHandler::getInstance(),
402-
$parameter
403-
);
400+
preg_match_all("/[$'][\w.$]+[$']/", $parameter, $match);
401+
if (!empty($match[0])) {
402+
$resolvedParameters[] = ltrim(rtrim($parameter, "'"), "'");
403+
} else {
404+
$resolvedParameters[] = $this->findAndReplaceReferences(
405+
DataObjectHandler::getInstance(),
406+
'{{' . $parameter . '}}'
407+
);
408+
}
404409
}
405410

406411
$resolveIndex = 0;

0 commit comments

Comments
 (0)