Skip to content

Commit 16d6880

Browse files
authored
Merge pull request #514 from magento/MQE-1711
MQE-1711: Switch between Developer mode and Production mode takes lon…
2 parents 4bbcab4 + f6a7763 commit 16d6880

File tree

10 files changed

+51
-18
lines changed

10 files changed

+51
-18
lines changed

dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ActionGroupWithStepKeyReferencesCest
4545
$I->fillField($action1); // stepKey: action1ActionGroup
4646
$I->comment("Invocation stepKey will be appended in non stepKey instances");
4747
$action3ActionGroup = $I->executeJS($action3ActionGroup); // stepKey: action3ActionGroup
48-
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\""); // stepKey: action4ActionGroup
48+
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, 60, "\"stuffHere\""); // stepKey: action4ActionGroup
4949
$I->comment($action4ActionGroup);
5050
$date = new \DateTime();
5151
$date->setTimestamp(strtotime("{$action5}"));

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,14 @@ class BasicFunctionalTestCest
126126
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector"); // stepKey: grabMultipleKey1
127127
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector"); // stepKey: grabTextFromKey1
128128
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); // stepKey: grabValueFromKey1
129-
$magentoCli1 = $I->magentoCLI("maintenance:enable", "\"stuffHere\""); // stepKey: magentoCli1
129+
$magentoCli1 = $I->magentoCLI("maintenance:enable", 60, "\"stuffHere\""); // stepKey: magentoCli1
130130
$I->comment($magentoCli1);
131+
$magentoCli2 = $I->magentoCLI("maintenance:enable", 120, "\"stuffHere\""); // stepKey: magentoCli2
132+
$I->comment($magentoCli2);
133+
$magentoCli3 = $I->magentoCLISecret("config:set somePath " . CredentialStore::getInstance()->getSecret("someKey"), 60); // stepKey: magentoCli3
134+
$I->comment($magentoCli3); // stepKey: magentoCli3
135+
$magentoCli4 = $I->magentoCLISecret("config:set somePath " . CredentialStore::getInstance()->getSecret("someKey"), 120); // stepKey: magentoCli4
136+
$I->comment($magentoCli4); // stepKey: magentoCli4
131137
$I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1
132138
$I->maximizeWindow(); // stepKey: maximizeWindowKey1
133139
$I->moveBack(); // stepKey: moveBackKey1

dev/tests/verification/Resources/DataReplacementTest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DataReplacementTestCest
5252
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: parameterArrayReplacementMSQBoth
5353
$I->selectMultipleOptions("#Doe" . msq("uniqueData"), "#element", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: multiSelectDataReplacement
5454
$I->fillField(".selector", "0"); // stepKey: insertZero
55-
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness"); // stepKey: insertCommand
55+
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness", 60); // stepKey: insertCommand
5656
$I->comment($insertCommand);
5757
$I->seeInPageSource("StringBefore John StringAfter"); // stepKey: htmlReplace1
5858
$I->seeInPageSource("#John"); // stepKey: htmlReplace2

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<grabTextFrom selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
7777
<grabValueFrom selector=".functionalTestSelector" stepKey="grabValueFromKey1" />
7878
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" stepKey="magentoCli1"/>
79+
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" timeout="120" stepKey="magentoCli2"/>
80+
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" stepKey="magentoCli3"/>
81+
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" timeout="120" stepKey="magentoCli4"/>
7982
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
8083
<maximizeWindow stepKey="maximizeWindowKey1"/>
8184
<moveBack stepKey="moveBackKey1"/>

docs/test/actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ Attribute|Type|Use|Description
12621262
---|---|---|---
12631263
`command`|string |optional| CLI command to be executed in Magento environment.
12641264
`arguments`|string |optional| Unescaped arguments to be passed in with the CLI command.
1265+
`timeout`|string|optional| Number of seconds CLI command can run without outputting anything.
12651266
`stepKey`|string|required| A unique identifier of the action.
12661267
`before`|string|optional| `stepKey` of action that must be executed next.
12671268
`after`|string|optional| `stepKey` of preceding action.

etc/config/command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
$tokenPassedIn = urldecode($_POST['token'] ?? '');
1515
$command = urldecode($_POST['command'] ?? '');
1616
$arguments = urldecode($_POST['arguments'] ?? '');
17+
$timeout = floatval(urldecode($_POST['timeout'] ?? 60));
1718

1819
// Token returned will be null if the token we passed in is invalid
1920
$tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken();
@@ -24,7 +25,7 @@
2425
if ($valid) {
2526
$fullCommand = escapeshellcmd($magentoBinary . " $command" . " $arguments");
2627
$process = new Symfony\Component\Process\Process($fullCommand);
27-
$process->setIdleTimeout(60);
28+
$process->setIdleTimeout($timeout);
2829
$process->setTimeout(0);
2930
$idleTimeout = false;
3031
try {

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,16 @@ public function scrollToTopOfPage()
511511
/**
512512
* Takes given $command and executes it against bin/magento or custom exposed entrypoint. Returns command output.
513513
*
514-
* @param string $command
515-
* @param string $arguments
514+
* @param string $command
515+
* @param integer $timeout
516+
* @param string $arguments
516517
* @return string
518+
*
517519
* @throws TestFrameworkException
518520
*/
519-
public function magentoCLI($command, $arguments = null)
521+
public function magentoCLI($command, $timeout = null, $arguments = null)
520522
{
521-
return $this->curlExecMagentoCLI($command, $arguments);
523+
return $this->curlExecMagentoCLI($command, $timeout, $arguments);
522524
//TODO: calling bin/magento from pipeline is timing out, needs investigation (ref: MQE-1774)
523525
// try {
524526
// return $this->shellExecMagentoCLI($command, $arguments);
@@ -673,17 +675,18 @@ public function fillSecretField($field, $value)
673675
* The data is decrypted immediately prior to data creation to avoid exposure in console or log.
674676
*
675677
* @param string $command
678+
* @param null $timeout
676679
* @param null $arguments
677680
* @throws TestFrameworkException
678681
* @return string
679682
*/
680-
public function magentoCLISecret($command, $arguments = null)
683+
public function magentoCLISecret($command, $timeout = null, $arguments = null)
681684
{
682685
// to protect any secrets from being printed to console the values are executed only at the webdriver level as a
683686
// decrypted value
684687

685688
$decryptedCommand = CredentialStore::getInstance()->decryptAllSecretsInString($command);
686-
return $this->magentoCLI($decryptedCommand, $arguments);
689+
return $this->magentoCLI($decryptedCommand, $timeout, $arguments);
687690
}
688691

689692
/**
@@ -835,20 +838,21 @@ public function makeScreenshot($name = null)
835838
/**
836839
* Takes given $command and executes it against bin/magento executable. Returns stdout output from the command.
837840
*
838-
* @param string $command
839-
* @param string $arguments
841+
* @param string $command
842+
* @param integer $timeout
843+
* @param string $arguments
840844
*
841845
* @throws \RuntimeException
842846
* @return string
843847
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
844848
*/
845-
private function shellExecMagentoCLI($command, $arguments): string
849+
private function shellExecMagentoCLI($command, $timeout, $arguments): string
846850
{
847851
$php = PHP_BINDIR ? PHP_BINDIR . DIRECTORY_SEPARATOR. 'php' : 'php';
848852
$binMagento = realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento');
849853
$command = $php . ' -f ' . $binMagento . ' ' . $command . ' ' . $arguments;
850854
$process = new Process(escapeshellcmd($command), MAGENTO_BP);
851-
$process->setIdleTimeout(60);
855+
$process->setIdleTimeout($timeout);
852856
$process->setTimeout(0);
853857
$exitCode = $process->run();
854858
if ($exitCode !== 0) {
@@ -861,12 +865,14 @@ private function shellExecMagentoCLI($command, $arguments): string
861865
/**
862866
* Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server.
863867
*
864-
* @param string $command
865-
* @param string $arguments
868+
* @param string $command
869+
* @param integer $timeout
870+
* @param string $arguments
871+
*
866872
* @return string
867873
* @throws TestFrameworkException
868874
*/
869-
private function curlExecMagentoCLI($command, $arguments): string
875+
private function curlExecMagentoCLI($command, $timeout, $arguments): string
870876
{
871877
// Remove index.php if it's present in url
872878
$baseUrl = rtrim(
@@ -887,6 +893,7 @@ private function curlExecMagentoCLI($command, $arguments): string
887893
'token' => $restExecutor->getAuthToken(),
888894
getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command,
889895
'arguments' => $arguments,
896+
'timeout' => $timeout,
890897
],
891898
CurlInterface::POST,
892899
[]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ActionObject
6363
const DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES = ["url", "createDataKey"];
6464
const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage'];
6565
const FUNCTION_CLOSURE_ACTIONS = ['waitForElementChange', 'performOn', 'executeInSelenium'];
66+
const COMMAND_ACTION_ATTRIBUTES = ['magentoCLI', 'magentoCLISecret'];
6667
const MERGE_ACTION_ORDER_AFTER = 'after';
6768
const MERGE_ACTION_ORDER_BEFORE = 'before';
6869
const ACTION_ATTRIBUTE_TIMEZONE = 'timezone';
@@ -71,6 +72,7 @@ class ActionObject
7172
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
7273
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/';
7374
const STRING_PARAMETER_REGEX = "/'[^']+'/";
75+
const DEFAULT_COMMAND_WAIT_TIMEOUT = 60;
7476
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
7577
const ACTION_TYPE_COMMENT = 'comment';
7678

src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
</xs:documentation>
5151
</xs:annotation>
5252
</xs:attribute>
53+
<xs:attribute type="xs:string" name="timeout">
54+
<xs:annotation>
55+
<xs:documentation>
56+
Idle timeout in seconds, defaulted to 60s when not specified.
57+
</xs:documentation>
58+
</xs:annotation>
59+
</xs:attribute>
5360
<xs:attributeGroup ref="commonActionAttributes"/>
5461
</xs:extension>
5562
</xs:simpleContent>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
613613
if (isset($customActionAttributes['timeout'])) {
614614
$time = $customActionAttributes['timeout'];
615615
}
616-
$time = $time ?? ActionObject::getDefaultWaitTimeout();
616+
617+
if (in_array($actionObject->getType(), ActionObject::COMMAND_ACTION_ATTRIBUTES)) {
618+
$time = $time ?? ActionObject::DEFAULT_COMMAND_WAIT_TIMEOUT;
619+
} else {
620+
$time = $time ?? ActionObject::getDefaultWaitTimeout();
621+
}
617622

618623
if (isset($customActionAttributes['parameterArray']) && $actionObject->getType() != 'pressKey') {
619624
// validate the param array is in the correct format
@@ -1282,6 +1287,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12821287
$actor,
12831288
$actionObject,
12841289
$command,
1290+
$time,
12851291
$arguments
12861292
);
12871293
$testSteps .= sprintf(self::STEP_KEY_ANNOTATION, $stepKey) . PHP_EOL;

0 commit comments

Comments
 (0)