Skip to content

Implement CLI command action #25

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
Jan 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
2 changes: 2 additions & 0 deletions dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<grabValueFrom stepKey="grabvalue12"/>
<loadSessionSnapshot stepKey="loadsession1"/>
<loadSessionSnapshot stepKey="loadsession12"/>
<magentoCLI stepKey="magentocli1"/>
<magentoCLI stepKey="magentocli2"/>
<makeScreenshot stepKey="screenshot1"/>
<makeScreenshot stepKey="screenshot12"/>
<maximizeWindow stepKey="maxwindow1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<grabMultiple selector=".functionalTestSelector" stepKey="grabMultipleKey1" />
<grabTextFrom selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
<grabValueFrom selector=".functionalTestSelector" stepKey="grabValueFromKey1" />
<magentoCLI command="maintenance:enable" stepKey="magentoCli1"/>
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
<maximizeWindow stepKey="maximizeWindowKey1"/>
<moveBack stepKey="moveBackKey1"/>
Expand Down
6 changes: 6 additions & 0 deletions dev/tests/verification/TestModule/Test/XmlDuplicateTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
<grabValueFrom stepKey="grabvalue12"/>
<loadSessionSnapshot stepKey="loadsession1"/>
<loadSessionSnapshot stepKey="loadsession12"/>
<magentoCLI stepKey="magentocli1"/>
<magentoCLI stepKey="magentocli2"/>
<makeScreenshot stepKey="screenshot1"/>
<makeScreenshot stepKey="screenshot12"/>
<maximizeWindow stepKey="maxwindow1"/>
Expand Down Expand Up @@ -318,6 +320,8 @@
<grabValueFrom stepKey="grabvalue12"/>
<loadSessionSnapshot stepKey="loadsession1"/>
<loadSessionSnapshot stepKey="loadsession12"/>
<magentoCLI stepKey="magentocli1"/>
<magentoCLI stepKey="magentocli2"/>
<makeScreenshot stepKey="screenshot1"/>
<makeScreenshot stepKey="screenshot12"/>
<maximizeWindow stepKey="maxwindow1"/>
Expand Down Expand Up @@ -529,6 +533,8 @@
<grabValueFrom stepKey="grabvalue12"/>
<loadSessionSnapshot stepKey="loadsession1"/>
<loadSessionSnapshot stepKey="loadsession12"/>
<magentoCLI stepKey="magentocli1"/>
<magentoCLI stepKey="magentocli2"/>
<makeScreenshot stepKey="screenshot1"/>
<makeScreenshot stepKey="screenshot12"/>
<maximizeWindow stepKey="maxwindow1"/>
Expand Down
12 changes: 6 additions & 6 deletions etc/di.xml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Codeception\Exception\ModuleException;
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;
Expand Down Expand Up @@ -390,6 +392,22 @@ public function scrollToTopOfPage()
$this->executeJS('window.scrollTo(0,0);');
}

/**
* Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server.
* @param string $command
* @returns string
*/
public function executeMagentoCLICommand($command)
{

$apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH');
$executor = new CurlTransport();
$executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []);
$response = $executor->read();
$executor->close();
return $response;
}

/**
* Conditional click for an area that should be visible
*
Expand Down
11 changes: 11 additions & 0 deletions src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<xs:element type="grabTextFromType" name="grabTextFrom" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="grabValueFromType" name="grabValueFrom" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="loadSessionSnapshotType" name="loadSessionSnapshot" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="magentoCLIType" name="magentoCLI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="makeScreenshotType" name="makeScreenshot" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="maximizeWindowType" name="maximizeWindow" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="moveBackType" name="moveBack" minOccurs="0" maxOccurs="unbounded"/>
Expand Down Expand Up @@ -814,6 +815,16 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="magentoCLIType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="command"/>
<xs:attribute type="xs:string" name="stepKey" use="required"/>
<xs:attribute type="xs:string" name="before"/>
<xs:attribute type="xs:string" name="after"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="makeScreenshotType">
<xs:simpleContent>
<xs:extension base="xs:string">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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);
}

Expand Down
18 changes: 18 additions & 0 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ private function generateStepsPhp($stepsObject, $hookObject = false)
$parameter = null;
$dependentSelector = null;
$visible = null;
$command = null;

$assertExpected = null;
$assertActual = null;
Expand All @@ -425,6 +426,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'];
}
Expand Down Expand Up @@ -1064,6 +1069,19 @@ private function generateStepsPhp($stepsObject, $hookObject = false)
$assertMessage
);
break;
case "magentoCLI":
$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);
}
Expand Down