Skip to content

Commit 8997ba3

Browse files
authored
MQE-585: Implement CLI command action
- Implemented test action.
1 parent 4c02c8b commit 8997ba3

File tree

9 files changed

+65
-7
lines changed

9 files changed

+65
-7
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class BasicFunctionalTestCest
7979
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector");
8080
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector");
8181
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector");
82+
$magentoCli1 = $I->executeMagentoCLICommand("maintenance:enable");
83+
$I->comment($magentoCli1);
8284
$I->makeScreenshot("screenShotInput");
8385
$I->maximizeWindow();
8486
$I->moveBack();

dev/tests/verification/TestModule/ActionGroup/XmlDuplicateActionGroup.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
<grabValueFrom stepKey="grabvalue12"/>
105105
<loadSessionSnapshot stepKey="loadsession1"/>
106106
<loadSessionSnapshot stepKey="loadsession12"/>
107+
<magentoCLI stepKey="magentocli1"/>
108+
<magentoCLI stepKey="magentocli2"/>
107109
<makeScreenshot stepKey="screenshot1"/>
108110
<makeScreenshot stepKey="screenshot12"/>
109111
<maximizeWindow stepKey="maxwindow1"/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<grabMultiple selector=".functionalTestSelector" stepKey="grabMultipleKey1" />
6060
<grabTextFrom selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
6161
<grabValueFrom selector=".functionalTestSelector" stepKey="grabValueFromKey1" />
62+
<magentoCLI command="maintenance:enable" stepKey="magentoCli1"/>
6263
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
6364
<maximizeWindow stepKey="maximizeWindowKey1"/>
6465
<moveBack stepKey="moveBackKey1"/>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
<grabValueFrom stepKey="grabvalue12"/>
107107
<loadSessionSnapshot stepKey="loadsession1"/>
108108
<loadSessionSnapshot stepKey="loadsession12"/>
109+
<magentoCLI stepKey="magentocli1"/>
110+
<magentoCLI stepKey="magentocli2"/>
109111
<makeScreenshot stepKey="screenshot1"/>
110112
<makeScreenshot stepKey="screenshot12"/>
111113
<maximizeWindow stepKey="maxwindow1"/>
@@ -318,6 +320,8 @@
318320
<grabValueFrom stepKey="grabvalue12"/>
319321
<loadSessionSnapshot stepKey="loadsession1"/>
320322
<loadSessionSnapshot stepKey="loadsession12"/>
323+
<magentoCLI stepKey="magentocli1"/>
324+
<magentoCLI stepKey="magentocli2"/>
321325
<makeScreenshot stepKey="screenshot1"/>
322326
<makeScreenshot stepKey="screenshot12"/>
323327
<maximizeWindow stepKey="maxwindow1"/>
@@ -529,6 +533,8 @@
529533
<grabValueFrom stepKey="grabvalue12"/>
530534
<loadSessionSnapshot stepKey="loadsession1"/>
531535
<loadSessionSnapshot stepKey="loadsession12"/>
536+
<magentoCLI stepKey="magentocli1"/>
537+
<magentoCLI stepKey="magentocli2"/>
532538
<makeScreenshot stepKey="screenshot1"/>
533539
<makeScreenshot stepKey="screenshot12"/>
534540
<maximizeWindow stepKey="maxwindow1"/>

etc/di.xml

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Codeception\Exception\ModuleException;
1818
use Codeception\Util\Uri;
1919
use Codeception\Util\ActionSequence;
20+
use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport;
21+
use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface;
2022
use Magento\Setup\Exception;
2123
use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil;
2224
use Yandex\Allure\Adapter\Support\AttachmentSupport;
@@ -390,6 +392,22 @@ public function scrollToTopOfPage()
390392
$this->executeJS('window.scrollTo(0,0);');
391393
}
392394

395+
/**
396+
* Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server.
397+
* @param string $command
398+
* @returns string
399+
*/
400+
public function executeMagentoCLICommand($command)
401+
{
402+
403+
$apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH');
404+
$executor = new CurlTransport();
405+
$executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []);
406+
$response = $executor->read();
407+
$executor->close();
408+
return $response;
409+
}
410+
393411
/**
394412
* Conditional click for an area that should be visible
395413
*

src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<xs:element type="grabTextFromType" name="grabTextFrom" minOccurs="0" maxOccurs="unbounded"/>
122122
<xs:element type="grabValueFromType" name="grabValueFrom" minOccurs="0" maxOccurs="unbounded"/>
123123
<xs:element type="loadSessionSnapshotType" name="loadSessionSnapshot" minOccurs="0" maxOccurs="unbounded"/>
124+
<xs:element type="magentoCLIType" name="magentoCLI" minOccurs="0" maxOccurs="unbounded"/>
124125
<xs:element type="makeScreenshotType" name="makeScreenshot" minOccurs="0" maxOccurs="unbounded"/>
125126
<xs:element type="maximizeWindowType" name="maximizeWindow" minOccurs="0" maxOccurs="unbounded"/>
126127
<xs:element type="moveBackType" name="moveBack" minOccurs="0" maxOccurs="unbounded"/>
@@ -814,6 +815,16 @@
814815
</xs:extension>
815816
</xs:simpleContent>
816817
</xs:complexType>
818+
<xs:complexType name="magentoCLIType">
819+
<xs:simpleContent>
820+
<xs:extension base="xs:string">
821+
<xs:attribute type="xs:string" name="command"/>
822+
<xs:attribute type="xs:string" name="stepKey" use="required"/>
823+
<xs:attribute type="xs:string" name="before"/>
824+
<xs:attribute type="xs:string" name="after"/>
825+
</xs:extension>
826+
</xs:simpleContent>
827+
</xs:complexType>
817828
<xs:complexType name="makeScreenshotType">
818829
<xs:simpleContent>
819830
<xs:extension base="xs:string">

src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function sanitizeWebDriverConfig($config, $params = ['url', 'selen
2525
$config['url'] = self::sanitizeUrl($config['url']);
2626
}
2727

28-
if (array_key_exists('selenium', array_flip($params))) {
28+
if (in_array('selenium', $params)) {
2929
$config = self::sanitizeSeleniumEnvs($config);
3030
}
3131

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ private function generateStepsPhp($stepsObject, $hookObject = false)
415415
$parameter = null;
416416
$dependentSelector = null;
417417
$visible = null;
418+
$command = null;
418419

419420
$assertExpected = null;
420421
$assertActual = null;
@@ -425,6 +426,10 @@ private function generateStepsPhp($stepsObject, $hookObject = false)
425426
// Validate action attributes and print notice messages on violation.
426427
$this->validateXmlAttributesMutuallyExclusive($stepKey, $actionName, $customActionAttributes);
427428

429+
if (isset($customActionAttributes['command'])) {
430+
$command = $customActionAttributes['command'];
431+
}
432+
428433
if (isset($customActionAttributes['attribute'])) {
429434
$attribute = $customActionAttributes['attribute'];
430435
}
@@ -1064,6 +1069,19 @@ private function generateStepsPhp($stepsObject, $hookObject = false)
10641069
$assertMessage
10651070
);
10661071
break;
1072+
case "magentoCLI":
1073+
$testSteps .= $this->wrapFunctionCallWithReturnValue(
1074+
$stepKey,
1075+
$actor,
1076+
"executeMagentoCLICommand",
1077+
$this->wrapWithDoubleQuotes($command)
1078+
);
1079+
$testSteps .= sprintf(
1080+
"\t\t$%s->comment(\$%s);\n",
1081+
$actor,
1082+
$stepKey
1083+
);
1084+
break;
10671085
default:
10681086
$testSteps .= $this->wrapFunctionCall($actor, $actionName, $selector, $input, $parameter);
10691087
}

0 commit comments

Comments
 (0)