Skip to content

MQE-1711: Switch between Developer mode and Production mode takes lon… #514

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 10 commits into from
Nov 26, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ActionGroupWithStepKeyReferencesCest
$I->fillField($action1); // stepKey: action1ActionGroup
$I->comment("Invocation stepKey will be appended in non stepKey instances");
$action3ActionGroup = $I->executeJS($action3ActionGroup); // stepKey: action3ActionGroup
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\""); // stepKey: action4ActionGroup
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, 60, "\"stuffHere\""); // stepKey: action4ActionGroup
$I->comment($action4ActionGroup);
$date = new \DateTime();
$date->setTimestamp(strtotime("{$action5}"));
Expand Down
8 changes: 7 additions & 1 deletion dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@ class BasicFunctionalTestCest
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector"); // stepKey: grabMultipleKey1
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector"); // stepKey: grabTextFromKey1
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); // stepKey: grabValueFromKey1
$magentoCli1 = $I->magentoCLI("maintenance:enable", "\"stuffHere\""); // stepKey: magentoCli1
$magentoCli1 = $I->magentoCLI("maintenance:enable", 60, "\"stuffHere\""); // stepKey: magentoCli1
$I->comment($magentoCli1);
$magentoCli2 = $I->magentoCLI("maintenance:enable", 120, "\"stuffHere\""); // stepKey: magentoCli2
$I->comment($magentoCli2);
$magentoCli3 = $I->magentoCLISecret("config:set somePath " . CredentialStore::getInstance()->getSecret("someKey"), 60); // stepKey: magentoCli3
$I->comment($magentoCli3); // stepKey: magentoCli3
$magentoCli4 = $I->magentoCLISecret("config:set somePath " . CredentialStore::getInstance()->getSecret("someKey"), 120); // stepKey: magentoCli4
$I->comment($magentoCli4); // stepKey: magentoCli4
$I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1
$I->maximizeWindow(); // stepKey: maximizeWindowKey1
$I->moveBack(); // stepKey: moveBackKey1
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/verification/Resources/DataReplacementTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DataReplacementTestCest
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: parameterArrayReplacementMSQBoth
$I->selectMultipleOptions("#Doe" . msq("uniqueData"), "#element", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: multiSelectDataReplacement
$I->fillField(".selector", "0"); // stepKey: insertZero
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness"); // stepKey: insertCommand
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness", 60); // stepKey: insertCommand
$I->comment($insertCommand);
$I->seeInPageSource("StringBefore John StringAfter"); // stepKey: htmlReplace1
$I->seeInPageSource("#John"); // stepKey: htmlReplace2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<grabTextFrom selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
<grabValueFrom selector=".functionalTestSelector" stepKey="grabValueFromKey1" />
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" stepKey="magentoCli1"/>
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" timeout="120" stepKey="magentoCli2"/>
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" stepKey="magentoCli3"/>
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" timeout="120" stepKey="magentoCli4"/>
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
<maximizeWindow stepKey="maximizeWindowKey1"/>
<moveBack stepKey="moveBackKey1"/>
Expand Down
1 change: 1 addition & 0 deletions docs/test/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ Attribute|Type|Use|Description
---|---|---|---
`command`|string |optional| CLI command to be executed in Magento environment.
`arguments`|string |optional| Unescaped arguments to be passed in with the CLI command.
`timeout`|string|optional| Number of seconds CLI command can run without outputting anything.
`stepKey`|string|required| A unique identifier of the action.
`before`|string|optional| `stepKey` of action that must be executed next.
`after`|string|optional| `stepKey` of preceding action.
Expand Down
3 changes: 2 additions & 1 deletion etc/config/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$tokenPassedIn = urldecode($_POST['token'] ?? '');
$command = urldecode($_POST['command'] ?? '');
$arguments = urldecode($_POST['arguments'] ?? '');
$timeout = floatval(urldecode($_POST['timeout'] ?? 60));

// Token returned will be null if the token we passed in is invalid
$tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken();
Expand All @@ -24,7 +25,7 @@
if ($valid) {
$fullCommand = escapeshellcmd($magentoBinary . " $command" . " $arguments");
$process = new Symfony\Component\Process\Process($fullCommand);
$process->setIdleTimeout(60);
$process->setIdleTimeout($timeout);
$process->setTimeout(0);
$idleTimeout = false;
try {
Expand Down
33 changes: 20 additions & 13 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,16 @@ public function scrollToTopOfPage()
/**
* Takes given $command and executes it against bin/magento or custom exposed entrypoint. Returns command output.
*
* @param string $command
* @param string $arguments
* @param string $command
* @param integer $timeout
* @param string $arguments
* @return string
*
* @throws TestFrameworkException
*/
public function magentoCLI($command, $arguments = null)
public function magentoCLI($command, $timeout = null, $arguments = null)
{
return $this->curlExecMagentoCLI($command, $arguments);
return $this->curlExecMagentoCLI($command, $timeout, $arguments);
//TODO: calling bin/magento from pipeline is timing out, needs investigation (ref: MQE-1774)
// try {
// return $this->shellExecMagentoCLI($command, $arguments);
Expand Down Expand Up @@ -673,17 +675,18 @@ public function fillSecretField($field, $value)
* The data is decrypted immediately prior to data creation to avoid exposure in console or log.
*
* @param string $command
* @param null $timeout
* @param null $arguments
* @throws TestFrameworkException
* @return string
*/
public function magentoCLISecret($command, $arguments = null)
public function magentoCLISecret($command, $timeout = null, $arguments = null)
{
// to protect any secrets from being printed to console the values are executed only at the webdriver level as a
// decrypted value

$decryptedCommand = CredentialStore::getInstance()->decryptAllSecretsInString($command);
return $this->magentoCLI($decryptedCommand, $arguments);
return $this->magentoCLI($decryptedCommand, $timeout, $arguments);
}

/**
Expand Down Expand Up @@ -835,20 +838,21 @@ public function makeScreenshot($name = null)
/**
* Takes given $command and executes it against bin/magento executable. Returns stdout output from the command.
*
* @param string $command
* @param string $arguments
* @param string $command
* @param integer $timeout
* @param string $arguments
*
* @throws \RuntimeException
* @return string
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
private function shellExecMagentoCLI($command, $arguments): string
private function shellExecMagentoCLI($command, $timeout, $arguments): string
{
$php = PHP_BINDIR ? PHP_BINDIR . DIRECTORY_SEPARATOR. 'php' : 'php';
$binMagento = realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento');
$command = $php . ' -f ' . $binMagento . ' ' . $command . ' ' . $arguments;
$process = new Process(escapeshellcmd($command), MAGENTO_BP);
$process->setIdleTimeout(60);
$process->setIdleTimeout($timeout);
$process->setTimeout(0);
$exitCode = $process->run();
if ($exitCode !== 0) {
Expand All @@ -861,12 +865,14 @@ private function shellExecMagentoCLI($command, $arguments): string
/**
* Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server.
*
* @param string $command
* @param string $arguments
* @param string $command
* @param integer $timeout
* @param string $arguments
*
* @return string
* @throws TestFrameworkException
*/
private function curlExecMagentoCLI($command, $arguments): string
private function curlExecMagentoCLI($command, $timeout, $arguments): string
{
// Remove index.php if it's present in url
$baseUrl = rtrim(
Expand All @@ -887,6 +893,7 @@ private function curlExecMagentoCLI($command, $arguments): string
'token' => $restExecutor->getAuthToken(),
getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command,
'arguments' => $arguments,
'timeout' => $timeout,
],
CurlInterface::POST,
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ActionObject
const DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES = ["url", "createDataKey"];
const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage'];
const FUNCTION_CLOSURE_ACTIONS = ['waitForElementChange', 'performOn', 'executeInSelenium'];
const COMMAND_ACTION_ATTRIBUTES = ['magentoCLI', 'magentoCLISecret'];
const MERGE_ACTION_ORDER_AFTER = 'after';
const MERGE_ACTION_ORDER_BEFORE = 'before';
const ACTION_ATTRIBUTE_TIMEZONE = 'timezone';
Expand All @@ -71,6 +72,7 @@ class ActionObject
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/';
const STRING_PARAMETER_REGEX = "/'[^']+'/";
const DEFAULT_COMMAND_WAIT_TIMEOUT = 60;
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
const ACTION_TYPE_COMMENT = 'comment';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute type="xs:string" name="timeout">
<xs:annotation>
<xs:documentation>
Idle timeout in seconds, defaulted to 60s when not specified.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="commonActionAttributes"/>
</xs:extension>
</xs:simpleContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
if (isset($customActionAttributes['timeout'])) {
$time = $customActionAttributes['timeout'];
}
$time = $time ?? ActionObject::getDefaultWaitTimeout();

if (in_array($actionObject->getType(), ActionObject::COMMAND_ACTION_ATTRIBUTES)) {
$time = $time ?? ActionObject::DEFAULT_COMMAND_WAIT_TIMEOUT;
} else {
$time = $time ?? ActionObject::getDefaultWaitTimeout();
}

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