Skip to content

MQE-1065: Persisted data are not resolved correctly when using with ParameterArray #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class BasicFunctionalTestCest
$I->pauseExecution();
$I->performOn("#selector", function(\WebDriverElement $el) {return $el->isDisplayed();});
$I->pressKey("#page", "a");
$I->pressKey("#page", ['ctrl','a'],'new');
$I->pressKey("#page", ['shift','111'],'1','x');
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
$I->pressKey("#page", ['ctrl', 'a'],'new');
$I->pressKey("#page", ['shift', '111'],'1','x');
$I->pressKey("#page", ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE);
$I->reloadPage();
$I->resetCookie("cookieInput");
$I->resizeWindow(0, 0);
Expand Down
6 changes: 6 additions & 0 deletions dev/tests/verification/Resources/ParameterArrayTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ class ParameterArrayTestCest
$I->unselectOption("#selector", ["postname" . msq("simpleParamData")]);
$I->unselectOption("#selector", [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
$I->unselectOption("#selector", ["name", PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
$I->pressKey("#selector", PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), ['ctrl', 'a'],\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
$I->pressKey("#selector", ['ctrl', 'a'], 10, 20,\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
$I->pressKey("#selector", ['ctrl', 'a'],'new', 10, 20,\Facebook\WebDriver\WebDriverKeys::DELETE,PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'));
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), 'a', "name"]);
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], 0, [PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('simpleDataKey', 'name', 'test')]);
$I->pressKey("#selector", ['ctrl', 'a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [msq("simpleParamData") . "prename", "postname" . msq("simpleParamData")]);
}
}
7 changes: 7 additions & 0 deletions dev/tests/verification/TestModule/Test/ParameterArrayTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@
<unselectOption selector="#selector" parameterArray="[{{simpleParamData.uniqueNamePost}}]" stepKey="004"/>
<unselectOption selector="#selector" parameterArray="[$simpleDataKey.name$]" stepKey="005"/>
<unselectOption selector="#selector" parameterArray="[{{simpleParamData.name}}, $simpleDataKey.name$]" stepKey="006"/>

<pressKey selector="#selector" parameterArray="[$simpleDataKey.name$, ['ctrl', 'a'], \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey001"/>
<pressKey selector="#selector" parameterArray="[['ctrl', 'a'], 10, 20, \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey002"/>
<pressKey selector="#selector" parameterArray="[['ctrl', 'a'], 'new', 10, 20, \Facebook\WebDriver\WebDriverKeys::DELETE, $simpleDataKey.name$]" stepKey="pressKey003"/>
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [$simpleDataKey.name$, 'a', {{simpleParamData.name}}]]" stepKey="pressKey004"/>
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], 0, [$simpleDataKey.name$, $simpleDataKey.name$]]" stepKey="pressKey005"/>
<pressKey selector="#selector" parameterArray="[['ctrl','a'],'new', 1, ['ctrl'], ['shift', 'ctrl', 'del'], [{{simpleParamData.uniqueNamePre}}, {{simpleParamData.uniqueNamePost}}]]" stepKey="pressKey006"/>
</test>
</tests>
84 changes: 66 additions & 18 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestGenerator
const TEST_SCOPE = 'test';
const HOOK_SCOPE = 'hook';
const SUITE_SCOPE = 'suite';
const PRESSKEY_ARRAY_ANCHOR_KEY = '987654321098765432109876543210';

/**
* Path to the export dir.
Expand Down Expand Up @@ -960,24 +961,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
case "pressKey":
$parameterArray = $customActionAttributes['parameterArray'] ?? null;
if ($parameterArray) {
// validate the param array is in the correct format
$this->validateParameterArray($parameterArray);

// trim off the outer braces and add commas for the regex match
$params = "," . substr($parameterArray, 1, strlen($parameterArray) - 2) . ",";

// we are matching any nested arrays for a simultaneous press, any string literals, and any
// explicit function calls from a class.
preg_match_all('/(\[.*?\])|(\'.*?\')|(\\\\.*?\,)/', $params, $paramInput);

//clean up the input by trimming any extra commas
$tmpParameterArray = [];
foreach ($paramInput[0] as $params) {
$tmpParameterArray[] = trim($params, ",");
}

// put the array together as a string to be passed as args
$parameterArray = implode(",", $tmpParameterArray);
$parameterArray = $this->processPressKey($parameterArray);
}
$testSteps .= $this->wrapFunctionCall(
$actor,
Expand Down Expand Up @@ -1642,6 +1626,70 @@ private function addUniquenessToParamArray($input)
return implode(", ", $result);
}

/**
* Process pressKey parameterArray attribute for uniqueness function call and necessary data resolutions
*
* @param string $input
* @return string
*/
private function processPressKey($input)
{
// validate the param array is in the correct format
$input = trim($input);
$this->validateParameterArray($input);
// trim off the outer braces
$input = substr($input, 1, strlen($input) - 2);

$result = [];
$arrayResult = [];
$count = 0;

// matches all arrays and replaces them with placeholder to prevent later param manipulation
preg_match_all('/[\[][^\]]*?[\]]/', $input, $paramInput);
if (!empty($paramInput)) {
foreach ($paramInput[0] as $param) {
$arrayResult[self::PRESSKEY_ARRAY_ANCHOR_KEY . $count] =
'[' . trim($this->addUniquenessToParamArray($param)) . ']';
$input = str_replace($param, self::PRESSKEY_ARRAY_ANCHOR_KEY . $count, $input);
$count++;
}
}

$paramArray = explode(",", $input);
foreach ($paramArray as $param) {
// matches strings wrapped in ', we assume these are string literals
if (preg_match('/^[\s]*(\'.*?\')[\s]*$/', $param)) {
$result[] = trim($param);
continue;
}

// matches \ for Facebook WebDriverKeys classes
if (substr(trim($param), 0, 1) === '\\') {
$result[] = trim($param);
continue;
}

// matches numbers
if (preg_match('/^[\s]*(\d+?)[\s]*$/', $param)) {
$result[] = $param;
continue;
}

$replacement = $this->addUniquenessFunctionCall(trim($param));

$result[] = $replacement;
}

$result = implode(',', $result);
// reinsert arrays into result
if (!empty($arrayResult)) {
foreach ($arrayResult as $key => $value) {
$result = str_replace($key, $value, $result);
}
}
return $result;
}

/**
* Add uniqueness function call to input string based on regex pattern.
*
Expand Down