Skip to content

Commit d02fe0c

Browse files
authored
Merge pull request magento#222 from magento/MQE-1065
MQE-1065: Persisted data are not resolved correctly when using with ParameterArray
2 parents c4d3307 + ded92ff commit d02fe0c

File tree

4 files changed

+82
-21
lines changed

4 files changed

+82
-21
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ class BasicFunctionalTestCest
128128
$I->pauseExecution();
129129
$I->performOn("#selector", function(\WebDriverElement $el) {return $el->isDisplayed();});
130130
$I->pressKey("#page", "a");
131-
$I->pressKey("#page", ['ctrl','a'],'new');
132-
$I->pressKey("#page", ['shift','111'],'1','x');
133-
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
131+
$I->pressKey("#page", ['ctrl', 'a'],'new');
132+
$I->pressKey("#page", ['shift', '111'],'1','x');
133+
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
134134
$I->reloadPage();
135135
$I->resetCookie("cookieInput");
136136
$I->resizeWindow(0, 0);

dev/tests/verification/Resources/ParameterArrayTest.txt

+6
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ class ParameterArrayTestCest
5151
$I->unselectOption("#selector", ["postname" . msq("simpleParamData")]);
5252
$I->unselectOption("#selector", [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
5353
$I->unselectOption("#selector", ["name", PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
54+
$I->pressKey("#selector", PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
55+
$I->pressKey("#selector", ['ctrl', 'a'], 10, 20,\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
56+
$I->pressKey("#selector", ['ctrl', 'a'],'new', 10, 20,\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
57+
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), 'a', "name"]);
58+
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], 0, [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
59+
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [msq("simpleParamData") . "prename", "postname" . msq("simpleParamData")]);
5460
}
5561
}

dev/tests/verification/TestModule/Test/ParameterArrayTest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,12 @@
2727
<unselectOption selector="#selector" parameterArray="[{{simpleParamData.uniqueNamePost}}]" stepKey="004"/>
2828
<unselectOption selector="#selector" parameterArray="[$simpleDataKey.name$]" stepKey="005"/>
2929
<unselectOption selector="#selector" parameterArray="[{{simpleParamData.name}}, $simpleDataKey.name$]" stepKey="006"/>
30+
31+
<pressKey selector="#selector" parameterArray="[$simpleDataKey.name$, ['ctrl', 'a'], \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey001"/>
32+
<pressKey selector="#selector" parameterArray="[['ctrl', 'a'], 10, 20, \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey002"/>
33+
<pressKey selector="#selector" parameterArray="[['ctrl', 'a'], 'new', 10, 20, \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey003"/>
34+
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [$simpleDataKey.name$, 'a', {{simpleParamData.name}}]]" stepKey="pressKey004"/>
35+
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], 0, [$simpleDataKey.name$, $simpleDataKey.name$]]" stepKey="pressKey005"/>
36+
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [{{simpleParamData.uniqueNamePre}}, {{simpleParamData.uniqueNamePost}}]]" stepKey="pressKey006"/>
3037
</test>
3138
</tests>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+66-18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TestGenerator
3737
const TEST_SCOPE = 'test';
3838
const HOOK_SCOPE = 'hook';
3939
const SUITE_SCOPE = 'suite';
40+
const PRESSKEY_ARRAY_ANCHOR_KEY = '987654321098765432109876543210';
4041

4142
/**
4243
* Path to the export dir.
@@ -960,24 +961,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
960961
case "pressKey":
961962
$parameterArray = $customActionAttributes['parameterArray'] ?? null;
962963
if ($parameterArray) {
963-
// validate the param array is in the correct format
964-
$this->validateParameterArray($parameterArray);
965-
966-
// trim off the outer braces and add commas for the regex match
967-
$params = "," . substr($parameterArray, 1, strlen($parameterArray) - 2) . ",";
968-
969-
// we are matching any nested arrays for a simultaneous press, any string literals, and any
970-
// explicit function calls from a class.
971-
preg_match_all('/(\[.*?\])|(\'.*?\')|(\\\\.*?\,)/', $params, $paramInput);
972-
973-
//clean up the input by trimming any extra commas
974-
$tmpParameterArray = [];
975-
foreach ($paramInput[0] as $params) {
976-
$tmpParameterArray[] = trim($params, ",");
977-
}
978-
979-
// put the array together as a string to be passed as args
980-
$parameterArray = implode(",", $tmpParameterArray);
964+
$parameterArray = $this->processPressKey($parameterArray);
981965
}
982966
$testSteps .= $this->wrapFunctionCall(
983967
$actor,
@@ -1642,6 +1626,70 @@ private function addUniquenessToParamArray($input)
16421626
return implode(", ", $result);
16431627
}
16441628

1629+
/**
1630+
* Process pressKey parameterArray attribute for uniqueness function call and necessary data resolutions
1631+
*
1632+
* @param string $input
1633+
* @return string
1634+
*/
1635+
private function processPressKey($input)
1636+
{
1637+
// validate the param array is in the correct format
1638+
$input = trim($input);
1639+
$this->validateParameterArray($input);
1640+
// trim off the outer braces
1641+
$input = substr($input, 1, strlen($input) - 2);
1642+
1643+
$result = [];
1644+
$arrayResult = [];
1645+
$count = 0;
1646+
1647+
// matches all arrays and replaces them with placeholder to prevent later param manipulation
1648+
preg_match_all('/[\[][^\]]*?[\]]/', $input, $paramInput);
1649+
if (!empty($paramInput)) {
1650+
foreach ($paramInput[0] as $param) {
1651+
$arrayResult[self::PRESSKEY_ARRAY_ANCHOR_KEY . $count] =
1652+
'[' . trim($this->addUniquenessToParamArray($param)) . ']';
1653+
$input = str_replace($param, self::PRESSKEY_ARRAY_ANCHOR_KEY . $count, $input);
1654+
$count++;
1655+
}
1656+
}
1657+
1658+
$paramArray = explode(",", $input);
1659+
foreach ($paramArray as $param) {
1660+
// matches strings wrapped in ', we assume these are string literals
1661+
if (preg_match('/^[\s]*(\'.*?\')[\s]*$/', $param)) {
1662+
$result[] = trim($param);
1663+
continue;
1664+
}
1665+
1666+
// matches \ for Facebook WebDriverKeys classes
1667+
if (substr(trim($param), 0, 1) === '\\') {
1668+
$result[] = trim($param);
1669+
continue;
1670+
}
1671+
1672+
// matches numbers
1673+
if (preg_match('/^[\s]*(\d+?)[\s]*$/', $param)) {
1674+
$result[] = $param;
1675+
continue;
1676+
}
1677+
1678+
$replacement = $this->addUniquenessFunctionCall(trim($param));
1679+
1680+
$result[] = $replacement;
1681+
}
1682+
1683+
$result = implode(',', $result);
1684+
// reinsert arrays into result
1685+
if (!empty($arrayResult)) {
1686+
foreach ($arrayResult as $key => $value) {
1687+
$result = str_replace($key, $value, $result);
1688+
}
1689+
}
1690+
return $result;
1691+
}
1692+
16451693
/**
16461694
* Add uniqueness function call to input string based on regex pattern.
16471695
*

0 commit comments

Comments
 (0)