From 898cbce8cef2da36d731b0e99f8171b7324c781e Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Mon, 8 Jan 2018 10:57:43 -0600 Subject: [PATCH 1/6] TEMP COMMIT For updating remotes. --- etc/di.xml | 12 +++++------ .../Module/MagentoWebDriver.php | 20 +++++++++++++++++++ .../Test/etc/testSchema.xsd | 11 ++++++++++ .../Util/TestGenerator.php | 8 ++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/etc/di.xml b/etc/di.xml index 61c89cf5b..b19850318 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -208,7 +208,7 @@ createDataKey createDataKey createDataKey - stepKey + stepKey keyForRemoval keyForRemoval keyForRemoval @@ -221,9 +221,9 @@ - stepKey - stepKey - stepKey + stepKey + stepKey + stepKey keyForRemoval keyForRemoval keyForRemoval @@ -292,7 +292,7 @@ name name - stepKey + stepKey keyForRemoval *ActionGroup.xml @@ -303,7 +303,7 @@ - stepKey + stepKey keyForRemoval name name diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 31249203d..c382f9e83 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -17,6 +17,13 @@ use Codeception\Exception\ModuleException; use Codeception\Util\Uri; use Codeception\Util\ActionSequence; +use Magento\AsynchronousOperations\Model\Operation; +use Magento\FunctionalTestingFramework\DataGenerator\Objects\OperationDefinitionObject; +use Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl\MagentoCLIExecutor; +use Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl\WebapiExecutor; +use Magento\FunctionalTestingFramework\DataGenerator\Persist\CurlHandler; +use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface; +use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; use Magento\Setup\Exception; use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil; use Yandex\Allure\Adapter\Support\AttachmentSupport; @@ -315,6 +322,19 @@ public function scrollToTopOfPage() $this->executeJS('window.scrollTo(0,0);'); } + /** + * Takes given $command and executes it against exposed MTF CLI entry point. + * @param string $command + */ + public function magentoCLI($command) + { + $apiURL = $this->config['url'] . $_ENV['MAGENTO_CLI_COMMAND_PATH']; + $executor = new CurlTransport(); + $executor->write($apiURL . '?' . $_ENV['MAGENTO_CLI_COMMAND_PARAMETER'] . '=' . $command, [], CurlInterface::GET, []); + $response = $executor->read(); + $executor->close(); + } + /** * Conditional click for an area that should be visible * diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd index 21acc45a0..6dfc33708 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd @@ -148,6 +148,7 @@ + @@ -852,6 +853,16 @@ + + + + + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 3687988fa..984695336 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -377,6 +377,7 @@ private function generateStepsPhp($stepsObject, $hookObject = false) $parameter = null; $dependentSelector = null; $visible = null; + $command = null; $assertExpected = null; $assertActual = null; @@ -387,6 +388,10 @@ private function generateStepsPhp($stepsObject, $hookObject = false) // Validate action attributes and print notice messages on violation. $this->validateXmlAttributesMutuallyExclusive($stepKey, $actionName, $customActionAttributes); + if (isset($customActionAttributes['command'])) { + $command = $customActionAttributes['command']; + } + if (isset($customActionAttributes['attribute'])) { $attribute = $customActionAttributes['attribute']; } @@ -1034,6 +1039,9 @@ private function generateStepsPhp($stepsObject, $hookObject = false) $assertMessage ); break; + case "magentoCLI": + $testSteps .= $this->wrapFunctionCall($actor, $actionName, $this->wrapWithDoubleQuotes($command)); + break; default: $testSteps .= $this->wrapFunctionCall($actor, $actionName, $selector, $input, $parameter); } From 82a0272f7e872c68533669bf986c3db2c2f13139 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Mon, 8 Jan 2018 14:25:58 -0600 Subject: [PATCH 2/6] MQE-585: Implement CLI command action - implement test action, add to schema and di. - add command variable to testgenerator --- etc/di.xml | 12 ++++++------ .../Module/MagentoWebDriver.php | 14 ++++++++++++++ .../Test/etc/testSchema.xsd | 11 +++++++++++ .../Util/TestGenerator.php | 8 ++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/etc/di.xml b/etc/di.xml index 61c89cf5b..b19850318 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -208,7 +208,7 @@ createDataKey createDataKey createDataKey - stepKey + stepKey keyForRemoval keyForRemoval keyForRemoval @@ -221,9 +221,9 @@ - stepKey - stepKey - stepKey + stepKey + stepKey + stepKey keyForRemoval keyForRemoval keyForRemoval @@ -292,7 +292,7 @@ name name - stepKey + stepKey keyForRemoval *ActionGroup.xml @@ -303,7 +303,7 @@ - stepKey + stepKey keyForRemoval name name diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 31249203d..e4bf66f2b 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -17,6 +17,7 @@ use Codeception\Exception\ModuleException; use Codeception\Util\Uri; use Codeception\Util\ActionSequence; +use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; use Magento\Setup\Exception; use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil; use Yandex\Allure\Adapter\Support\AttachmentSupport; @@ -315,6 +316,19 @@ public function scrollToTopOfPage() $this->executeJS('window.scrollTo(0,0);'); } + /** + * Takes given $command and executes it against exposed MTF CLI entry point. + * @param string $command + */ + public function magentoCLI($command) + { + $apiURL = $this->config['url'] . $_ENV['MAGENTO_CLI_COMMAND_PATH']; + $executor = new CurlTransport(); + $executor->write($apiURL . '?' . $_ENV['MAGENTO_CLI_COMMAND_PARAMETER'] . '=' . $command, [], CurlInterface::GET, []); + $response = $executor->read(); + $executor->close(); + } + /** * Conditional click for an area that should be visible * diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd index 21acc45a0..6dfc33708 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd @@ -148,6 +148,7 @@ + @@ -852,6 +853,16 @@ + + + + + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 3687988fa..984695336 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -377,6 +377,7 @@ private function generateStepsPhp($stepsObject, $hookObject = false) $parameter = null; $dependentSelector = null; $visible = null; + $command = null; $assertExpected = null; $assertActual = null; @@ -387,6 +388,10 @@ private function generateStepsPhp($stepsObject, $hookObject = false) // Validate action attributes and print notice messages on violation. $this->validateXmlAttributesMutuallyExclusive($stepKey, $actionName, $customActionAttributes); + if (isset($customActionAttributes['command'])) { + $command = $customActionAttributes['command']; + } + if (isset($customActionAttributes['attribute'])) { $attribute = $customActionAttributes['attribute']; } @@ -1034,6 +1039,9 @@ private function generateStepsPhp($stepsObject, $hookObject = false) $assertMessage ); break; + case "magentoCLI": + $testSteps .= $this->wrapFunctionCall($actor, $actionName, $this->wrapWithDoubleQuotes($command)); + break; default: $testSteps .= $this->wrapFunctionCall($actor, $actionName, $selector, $input, $parameter); } From 57df3f8e5abe3a9a72bb07b8de85d242ddff0ae0 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 9 Jan 2018 09:52:43 -0600 Subject: [PATCH 3/6] MQE-585: Implement CLI command action - cli envs are not stored in webdriver config and used there. Also sanitized via the existing util - custom method renamed for test cleanliness. action is still magnetoCLI, but mapping happens at TestGenerator level. - Verification test changes. --- .../Resources/BasicFunctionalTest.txt | 2 ++ .../TestModule/Test/BasicFunctionalTest.xml | 1 + .../Module/MagentoWebDriver.php | 14 ++++++++++---- .../Util/ConfigSanitizerUtil.php | 16 ++++++++++++++++ .../Util/TestGenerator.php | 12 +++++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/dev/tests/verification/Resources/BasicFunctionalTest.txt b/dev/tests/verification/Resources/BasicFunctionalTest.txt index 13ae49a63..c11e36382 100644 --- a/dev/tests/verification/Resources/BasicFunctionalTest.txt +++ b/dev/tests/verification/Resources/BasicFunctionalTest.txt @@ -78,6 +78,8 @@ class BasicFunctionalTestCest $grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector"); $grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector"); $grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); + $magentoCli1 = $I->executeMagentoCLICommand("maintenance:enable"); + $I->comment($magentoCli1); $I->makeScreenshot("screenShotInput"); $I->maximizeWindow(); $I->moveBack(); diff --git a/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml b/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml index 081fff787..ddd5bf3f0 100644 --- a/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml +++ b/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml @@ -59,6 +59,7 @@ + diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index e4bf66f2b..8e892fcca 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -18,6 +18,7 @@ use Codeception\Util\Uri; use Codeception\Util\ActionSequence; use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; +use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface; use Magento\Setup\Exception; use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil; use Yandex\Allure\Adapter\Support\AttachmentSupport; @@ -82,6 +83,7 @@ class MagentoWebDriver extends WebDriver public function _initialize() { $this->config = ConfigSanitizerUtil::sanitizeWebDriverConfig($this->config); + $this->config = ConfigSanitizerUtil::sanitizeCliCommandEnvs($this->config); parent::_initialize(); } @@ -89,6 +91,7 @@ public function _resetConfig() { parent::_resetConfig(); $this->config = ConfigSanitizerUtil::sanitizeWebDriverConfig($this->config); + $this->config = ConfigSanitizerUtil::sanitizeCliCommandEnvs($this->config); } /** @@ -317,16 +320,19 @@ public function scrollToTopOfPage() } /** - * Takes given $command and executes it against exposed MTF CLI entry point. + * Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server. * @param string $command + * @returns string */ - public function magentoCLI($command) + public function executeMagentoCLICommand($command) { - $apiURL = $this->config['url'] . $_ENV['MAGENTO_CLI_COMMAND_PATH']; + + $apiURL = $this->config['url'] . $this->config['MAGENTO_CLI_COMMAND_PATH']; $executor = new CurlTransport(); - $executor->write($apiURL . '?' . $_ENV['MAGENTO_CLI_COMMAND_PARAMETER'] . '=' . $command, [], CurlInterface::GET, []); + $executor->write($apiURL, [$this->config['MAGENTO_CLI_COMMAND_PARAMETER'] => $command], CurlInterface::POST, []); $response = $executor->read(); $executor->close(); + return $response; } /** diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index 8dac6a1e6..db1ebf02d 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -54,6 +54,22 @@ private static function sanitizeSeleniumEnvs($config) return $config; } + /** + * Determines if CLI Command env variables are set, and sets them if they aren't. + * @param array $config + * @return array + */ + public static function sanitizeCliCommandEnvs($config) + { + if (!isset($config['MAGENTO_CLI_COMMAND_PATH'])) { + $config['MAGENTO_CLI_COMMAND_PATH'] = "dev/tests/acceptance/utils/command.php"; + } + if (!isset($config['MAGENTO_CLI_COMMAND_PARAMETER'])) { + $config['MAGENTO_CLI_COMMAND_PARAMETER'] = "command"; + } + return $config; + } + /** * Method which validates env vars have been properly read into the config. Method implemented as part of * bug MQE-567 diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index cec19dbc8..c4ff2ce44 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1071,7 +1071,17 @@ private function generateStepsPhp($stepsObject, $hookObject = false) ); break; case "magentoCLI": - $testSteps .= $this->wrapFunctionCall($actor, $actionName, $this->wrapWithDoubleQuotes($command)); + $testSteps .= $this->wrapFunctionCallWithReturnValue( + $stepKey, + $actor, + "executeMagentoCLICommand", + $this->wrapWithDoubleQuotes($command) + ); + $testSteps .= sprintf( + "\t\t$%s->comment(\$%s);\n", + $actor, + $stepKey + ); break; default: $testSteps .= $this->wrapFunctionCall($actor, $actionName, $selector, $input, $parameter); From d839bf8a06d0bd0592933068a4d2b8f35d78f2e9 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Thu, 11 Jan 2018 13:57:04 -0600 Subject: [PATCH 4/6] MQE-585: Implement CLI command action - CR fixes. --- .../Module/MagentoWebDriver.php | 2 -- .../Util/ConfigSanitizerUtil.php | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 8e892fcca..533e601be 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -83,7 +83,6 @@ class MagentoWebDriver extends WebDriver public function _initialize() { $this->config = ConfigSanitizerUtil::sanitizeWebDriverConfig($this->config); - $this->config = ConfigSanitizerUtil::sanitizeCliCommandEnvs($this->config); parent::_initialize(); } @@ -91,7 +90,6 @@ public function _resetConfig() { parent::_resetConfig(); $this->config = ConfigSanitizerUtil::sanitizeWebDriverConfig($this->config); - $this->config = ConfigSanitizerUtil::sanitizeCliCommandEnvs($this->config); } /** diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index db1ebf02d..411bc90fc 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -17,7 +17,7 @@ class ConfigSanitizerUtil * @param String[] $params * @return array */ - public static function sanitizeWebDriverConfig($config, $params = ['url', 'selenium']) + public static function sanitizeWebDriverConfig($config, $params = ['url', 'selenium', 'cli']) { self::validateConfigBasedVars($config); @@ -25,10 +25,14 @@ public static function sanitizeWebDriverConfig($config, $params = ['url', 'selen $config['url'] = self::sanitizeUrl($config['url']); } - if (array_key_exists('selenium', array_flip($params))) { + if (in_array('selenium', $params)) { $config = self::sanitizeSeleniumEnvs($config); } + if (in_array('cli', $params)) { + $config = self::sanitizeCliCommandEnvs($config); + } + return $config; } From 5c898429463610278a77ba6e838b40d7e6514de1 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 16 Jan 2018 14:49:17 -0600 Subject: [PATCH 5/6] MQE-585: Implement CLI command action - CR fixes. --- .../Module/MagentoWebDriver.php | 4 ++-- .../Util/ConfigSanitizerUtil.php | 22 +------------------ 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index fa8cb7030..cde8f2cbf 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -414,9 +414,9 @@ public function scrollToTopOfPage() public function executeMagentoCLICommand($command) { - $apiURL = $this->config['url'] . $this->config['MAGENTO_CLI_COMMAND_PATH']; + $apiURL = $this->config['url'] . $_ENV['MAGENTO_CLI_COMMAND_PATH']; $executor = new CurlTransport(); - $executor->write($apiURL, [$this->config['MAGENTO_CLI_COMMAND_PARAMETER'] => $command], CurlInterface::POST, []); + $executor->write($apiURL, [$_ENV['MAGENTO_CLI_COMMAND_PARAMETER'] => $command], CurlInterface::POST, []); $response = $executor->read(); $executor->close(); return $response; diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index 411bc90fc..e09bf2cc3 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -17,7 +17,7 @@ class ConfigSanitizerUtil * @param String[] $params * @return array */ - public static function sanitizeWebDriverConfig($config, $params = ['url', 'selenium', 'cli']) + public static function sanitizeWebDriverConfig($config, $params = ['url', 'selenium']) { self::validateConfigBasedVars($config); @@ -29,10 +29,6 @@ public static function sanitizeWebDriverConfig($config, $params = ['url', 'selen $config = self::sanitizeSeleniumEnvs($config); } - if (in_array('cli', $params)) { - $config = self::sanitizeCliCommandEnvs($config); - } - return $config; } @@ -58,22 +54,6 @@ private static function sanitizeSeleniumEnvs($config) return $config; } - /** - * Determines if CLI Command env variables are set, and sets them if they aren't. - * @param array $config - * @return array - */ - public static function sanitizeCliCommandEnvs($config) - { - if (!isset($config['MAGENTO_CLI_COMMAND_PATH'])) { - $config['MAGENTO_CLI_COMMAND_PATH'] = "dev/tests/acceptance/utils/command.php"; - } - if (!isset($config['MAGENTO_CLI_COMMAND_PARAMETER'])) { - $config['MAGENTO_CLI_COMMAND_PARAMETER'] = "command"; - } - return $config; - } - /** * Method which validates env vars have been properly read into the config. Method implemented as part of * bug MQE-567 From 0c42c5c886fde87b6bc42e387af43c4d593fecc7 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 16 Jan 2018 15:28:01 -0600 Subject: [PATCH 6/6] MQE-585: Implement CLI command action - more CR fixes --- .../FunctionalTestingFramework/Module/MagentoWebDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index cde8f2cbf..d8e150f58 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -414,9 +414,9 @@ public function scrollToTopOfPage() public function executeMagentoCLICommand($command) { - $apiURL = $this->config['url'] . $_ENV['MAGENTO_CLI_COMMAND_PATH']; + $apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH'); $executor = new CurlTransport(); - $executor->write($apiURL, [$_ENV['MAGENTO_CLI_COMMAND_PARAMETER'] => $command], CurlInterface::POST, []); + $executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []); $response = $executor->read(); $executor->close(); return $response;