Skip to content

Commit 8a1525c

Browse files
committed
MQE-1065: Persisted data are not resolved correctly when using with ParameterArray
- bug fix
1 parent 31ddcc8 commit 8a1525c

File tree

4 files changed

+74
-21
lines changed

4 files changed

+74
-21
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class BasicFunctionalTestCest
124124
$I->pauseExecution();
125125
$I->performOn("#selector", function(\WebDriverElement $el) {return $el->isDisplayed();});
126126
$I->pressKey("#page", "a");
127-
$I->pressKey("#page", ['ctrl','a'],'new');
128-
$I->pressKey("#page", ['shift','111'],'1','x');
129-
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
127+
$I->pressKey("#page", ['ctrl', 'a'],'new');
128+
$I->pressKey("#page", ['shift', '111'],'1','x');
129+
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
130130
$I->reloadPage();
131131
$I->resetCookie("cookieInput");
132132
$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

+58-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,62 @@ private function addUniquenessToParamArray($input)
16421626
return implode(", ", $result);
16431627
}
16441628

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

0 commit comments

Comments
 (0)