From 8f60fa88ce9b51e777d87c70e6c6176bf99081ed Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Mon, 13 Jul 2020 09:15:12 -0500 Subject: [PATCH 1/4] MQE-1886: Ability to use grab data between ActionGroups --- .../ActionGroupReturningValueTest.txt | 75 +++++++++++++++++++ ...lActionGroupWithReturnValueActionGroup.xml | 14 ++++ .../ActionGroupReturningValueTest.xml | 30 ++++++++ .../Tests/ActionGroupGenerationTest.php | 11 +++ docs/test/action-groups.md | 28 +++++++ docs/test/actions.md | 29 +++++++ etc/di.xml | 2 +- .../Module/MagentoWebDriver.php | 12 +++ .../Test/etc/Actions/customActions.xsd | 26 +++++++ .../Test/etc/actionTypeTags.xsd | 6 ++ .../Test/etc/mergedActionGroupSchema.xsd | 62 +++++++++------ .../Util/TestGenerator.php | 10 +++ 12 files changed, 281 insertions(+), 24 deletions(-) create mode 100644 dev/tests/verification/Resources/ActionGroupReturningValueTest.txt create mode 100644 dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/FunctionalActionGroupWithReturnValueActionGroup.xml create mode 100644 dev/tests/verification/TestModule/Test/ActionGroupFunctionalTest/ActionGroupReturningValueTest.xml diff --git a/dev/tests/verification/Resources/ActionGroupReturningValueTest.txt b/dev/tests/verification/Resources/ActionGroupReturningValueTest.txt new file mode 100644 index 000000000..08e0b44f8 --- /dev/null +++ b/dev/tests/verification/Resources/ActionGroupReturningValueTest.txt @@ -0,0 +1,75 @@ +Test filesverification/TestModule/Test/ActionGroupFunctionalTest/ActionGroupReturningValueTest.xml
") + */ +class ActionGroupReturningValueTestCest +{ + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _before(AcceptanceTester $I) + { + $I->createEntity("createPersonParam", "hook", "ReplacementPerson", [], []); // stepKey: createPersonParam + $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); + $I->fillField("#foo", "myData1"); // stepKey: fillField1BeforeGroup + $I->fillField("#bar", "myData2"); // stepKey: fillField2BeforeGroup + $I->comment("Exiting Action Group [beforeGroup] FunctionalActionGroup"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _after(AcceptanceTester $I) + { + $I->comment("Entering Action Group [afterGroup] FunctionalActionGroup"); + $I->fillField("#foo", "myData1"); // stepKey: fillField1AfterGroup + $I->fillField("#bar", "myData2"); // stepKey: fillField2AfterGroup + $I->comment("Exiting Action Group [afterGroup] FunctionalActionGroup"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _failed(AcceptanceTester $I) + { + $I->saveScreenshot(); // stepKey: saveScreenshot + } + + /** + * @Severity(level = SeverityLevel::CRITICAL) + * @Features({"TestModule"}) + * @Stories({"MQE-433"}) + * @Parameter(name = "AcceptanceTester", value="$I") + * @param AcceptanceTester $I + * @return void + * @throws \Exception + */ + public function ActionGroupReturningValueTest(AcceptanceTester $I) + { + $I->amOnPage("/someUrl"); // stepKey: step1 + $I->comment("Entering Action Group [actionGroupWithReturnValue1] FunctionalActionGroupWithReturnValueActionGroup"); + $grabTextFrom1ActionGroupWithReturnValue1 = $I->grabTextFrom("#foo"); // stepKey: grabTextFrom1ActionGroupWithReturnValue1 + $actionGroupWithReturnValue1 = $I->return($grabTextFrom1ActionGroupWithReturnValue1); // stepKey: returnActionGroupWithReturnValue1 + $I->comment("Exiting Action Group [actionGroupWithReturnValue1] FunctionalActionGroupWithReturnValueActionGroup"); + $I->comment("Entering Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + $I->see($actionGroupWithReturnValue1, "#element .{$actionGroupWithReturnValue1}"); // stepKey: see1ActionGroupWithStringUsage1 + $I->comment("Exiting Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + } +} diff --git a/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/FunctionalActionGroupWithReturnValueActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/FunctionalActionGroupWithReturnValueActionGroup.xml new file mode 100644 index 000000000..77900efd3 --- /dev/null +++ b/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/FunctionalActionGroupWithReturnValueActionGroup.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/dev/tests/verification/TestModule/Test/ActionGroupFunctionalTest/ActionGroupReturningValueTest.xml b/dev/tests/verification/TestModule/Test/ActionGroupFunctionalTest/ActionGroupReturningValueTest.xml new file mode 100644 index 000000000..ade1f51db --- /dev/null +++ b/dev/tests/verification/TestModule/Test/ActionGroupFunctionalTest/ActionGroupReturningValueTest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/tests/verification/Tests/ActionGroupGenerationTest.php b/dev/tests/verification/Tests/ActionGroupGenerationTest.php index 3f9412aec..4b888407f 100644 --- a/dev/tests/verification/Tests/ActionGroupGenerationTest.php +++ b/dev/tests/verification/Tests/ActionGroupGenerationTest.php @@ -228,4 +228,15 @@ public function testActionGroupWithActionStepKeyReferencesInSelectors() { $this->generateAndCompareTest('ActionGroupWithParameterizedElementsWithStepKeyReferences'); } + + /** + * Test generation of a test referencing an action group that returns a value. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testActionGroupReturningValue() + { + $this->generateAndCompareTest('ActionGroupReturningValueTest'); + } } diff --git a/docs/test/action-groups.md b/docs/test/action-groups.md index 70af0621a..80caf0883 100644 --- a/docs/test/action-groups.md +++ b/docs/test/action-groups.md @@ -180,6 +180,34 @@ MFTF resolves `{{myCustomEntity.field1}}` the same as it would in a `selector` o ``` +## Returning a value + +Action groups can return a value using `` action. + +```xml + + + + + +``` + +This value can be accessed as below: + +1. Reference `GetOrderIdActionGroup` action group: +```xml + + +``` + +1. To use the value returned in another action group, using action group stepKey {getOrderId}: +```xml + + + + +``` + ## Optimizing action group structures Structuring properly an action group increases code reusability and readability. diff --git a/docs/test/actions.md b/docs/test/actions.md index 1d2f83802..1bfffe748 100644 --- a/docs/test/actions.md +++ b/docs/test/actions.md @@ -151,6 +151,7 @@ The following test actions return a variable: * [grabValueFrom](#grabvaluefrom) * [executeJS](#executejs) * [getOTP](#getotp) +* [return](#return) Learn more in [Using data returned by test actions](../data.md#use-data-returned-by-test-actions). @@ -1240,6 +1241,34 @@ To access this value, use `{$grabInputName}` in later actions. --> ``` +### return + +Allows action group to return a value. Value can be then accessed in the test using the action group stepKey. + +Attribute|Type|Use|Description +---|---|---|--- +`value`|string|required| value returned by actionGroup. +`stepKey`|string|required| A unique identifier of the action. + +#### Example + +```xml + + + + + +``` +```xml + + + + + + + +``` + ### loadSessionSnapshot See [loadSessionSnapshot docs on codeception.com](http://codeception.com/docs/modules/WebDriver#loadSessionSnapshot). diff --git a/etc/di.xml b/etc/di.xml index e561911da..f5184808c 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -8,7 +8,7 @@ + ]> diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 2f4745df1..944735677 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -1122,4 +1122,16 @@ public function switchToIFrame($locator = null) $this->webDriver->switchTo()->frame($els[0]); } } + + /** + * Returns a value to origin of the action. + * TODO: move this function to MagentoActionProxies after MQE-1904 + * + * @param mixed $value + * @return mixed + */ + public function return($value) + { + return $value; + } } diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd index 2aad30c75..64fbaeaed 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd @@ -29,6 +29,12 @@ + + + + + + @@ -346,6 +352,26 @@ + + + + Used in an action group to return a value. Must be used only once in action group. Do not use in tests or suites. + + + + + + + + Value to be returned. + + + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/actionTypeTags.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/actionTypeTags.xsd index def2964af..d68cf43db 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/actionTypeTags.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/actionTypeTags.xsd @@ -68,6 +68,12 @@ + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/mergedActionGroupSchema.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/mergedActionGroupSchema.xsd index bd32ba879..f45c33acd 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/mergedActionGroupSchema.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/mergedActionGroupSchema.xsd @@ -15,29 +15,21 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -57,4 +49,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 8253a75ba..80056b3b9 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1172,6 +1172,16 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $selector ); break; + case "return": + $actionOrigin = $actionObject->getActionOrigin(); + $actionOriginStepKey = $actionOrigin[ActionGroupObject::ACTION_GROUP_ORIGIN_TEST_REF]; + $testSteps .= $this->wrapFunctionCallWithReturnValue( + $actionOriginStepKey, + $actor, + $actionObject, + $value + ); + break; case "formatCurrency": $testSteps .= $this->wrapFunctionCallWithReturnValue( $stepKey, From 324bb682a3543c4821659bff77f161405494fa1e Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Mon, 20 Jul 2020 13:06:06 -0500 Subject: [PATCH 2/4] MQE-1886: Ability to use grab data between ActionGroups verification tests + other fixes --- .../ExtendedActionGroupReturningValueTest.txt | 40 ++++++++++ ...ndedChildActionGroupReturningValueTest.txt | 43 +++++++++++ .../MergedActionGroupReturningValueTest.txt | 77 +++++++++++++++++++ .../ActionGroupReturningValueActionGroup.xml | 21 +++++ ...edActionGroupReturningValueActionGroup.xml | 21 +++++ ...geActionGroupReturningValueActionGroup.xml | 19 +++++ ...geActionGroupReturningValueActionGroup.xml | 14 ++++ .../ExtendedActionGroupReturningValueTest.xml | 22 ++++++ ...ndedChildActionGroupReturningValueTest.xml | 23 ++++++ .../MergedActionGroupReturningValueTest.xml | 32 ++++++++ .../ActionGroupWithReturnGenerationTest.php | 52 +++++++++++++ docs/data.md | 2 + docs/test/action-groups.md | 22 +++--- docs/test/actions.md | 21 +---- 14 files changed, 381 insertions(+), 28 deletions(-) create mode 100644 dev/tests/verification/Resources/ExtendedActionGroupReturningValueTest.txt create mode 100644 dev/tests/verification/Resources/ExtendedChildActionGroupReturningValueTest.txt create mode 100644 dev/tests/verification/Resources/MergedActionGroupReturningValueTest.txt create mode 100644 dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ActionGroupReturningValueActionGroup.xml create mode 100644 dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ExtendedActionGroupReturningValueActionGroup.xml create mode 100644 dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml create mode 100644 dev/tests/verification/TestModule/ActionGroup/MergeFunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml create mode 100644 dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedActionGroupReturningValueTest.xml create mode 100644 dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedChildActionGroupReturningValueTest.xml create mode 100644 dev/tests/verification/TestModule/Test/MergeFunctionalTest/MergedActionGroupReturningValueTest.xml create mode 100644 dev/tests/verification/Tests/ActionGroupWithReturnGenerationTest.php diff --git a/dev/tests/verification/Resources/ExtendedActionGroupReturningValueTest.txt b/dev/tests/verification/Resources/ExtendedActionGroupReturningValueTest.txt new file mode 100644 index 000000000..2f26a6463 --- /dev/null +++ b/dev/tests/verification/Resources/ExtendedActionGroupReturningValueTest.txt @@ -0,0 +1,40 @@ +Test filesverification/TestModule/Test/ActionGroupTest/ExtendedActionGroupReturningValueTest.xml
") + */ +class ExtendedActionGroupReturningValueTestCest +{ + /** + * @Severity(level = SeverityLevel::CRITICAL) + * @Features({"TestModule"}) + * @Parameter(name = "AcceptanceTester", value="$I") + * @param AcceptanceTester $I + * @return void + * @throws \Exception + */ + public function ExtendedActionGroupReturningValueTest(AcceptanceTester $I) + { + $I->comment("Entering Action Group [actionGroupReturningValue] ActionGroupReturningValueActionGroup"); + $grabProducts1ActionGroupReturningValue = $I->grabMultiple("selector"); // stepKey: grabProducts1ActionGroupReturningValue + $I->assertCount(99, $grabProducts1ActionGroupReturningValue); // stepKey: assertCountActionGroupReturningValue + $actionGroupReturningValue = $I->return($grabProducts1ActionGroupReturningValue); // stepKey: returnProducts1ActionGroupReturningValue + $I->comment("Exiting Action Group [actionGroupReturningValue] ActionGroupReturningValueActionGroup"); + $I->comment("Entering Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + $I->see($actionGroupReturningValue, "#element .{$actionGroupReturningValue}"); // stepKey: see1ActionGroupWithStringUsage1 + $I->comment("Exiting Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + } +} diff --git a/dev/tests/verification/Resources/ExtendedChildActionGroupReturningValueTest.txt b/dev/tests/verification/Resources/ExtendedChildActionGroupReturningValueTest.txt new file mode 100644 index 000000000..d043a5c04 --- /dev/null +++ b/dev/tests/verification/Resources/ExtendedChildActionGroupReturningValueTest.txt @@ -0,0 +1,43 @@ +Test filesverification/TestModule/Test/ActionGroupTest/ExtendedChildActionGroupReturningValueTest.xml
") + */ +class ExtendedChildActionGroupReturningValueTestCest +{ + /** + * @Severity(level = SeverityLevel::CRITICAL) + * @Features({"TestModule"}) + * @Parameter(name = "AcceptanceTester", value="$I") + * @param AcceptanceTester $I + * @return void + * @throws \Exception + */ + public function ExtendedChildActionGroupReturningValueTest(AcceptanceTester $I) + { + $I->comment("Entering Action Group [extendedActionGroupReturningValue] ExtendedActionGroupReturningValueActionGroup"); + $grabProducts1ExtendedActionGroupReturningValue = $I->grabMultiple("selector"); // stepKey: grabProducts1ExtendedActionGroupReturningValue + $I->assertCount(99, $grabProducts1ExtendedActionGroupReturningValue); // stepKey: assertCountExtendedActionGroupReturningValue + $extendedActionGroupReturningValue = $I->return($grabProducts1ExtendedActionGroupReturningValue); // stepKey: returnProducts1ExtendedActionGroupReturningValue + $grabProducts2ExtendedActionGroupReturningValue = $I->grabMultiple("otherSelector"); // stepKey: grabProducts2ExtendedActionGroupReturningValue + $I->assertCount(8000, $grabProducts2ExtendedActionGroupReturningValue); // stepKey: assertSecondCountExtendedActionGroupReturningValue + $extendedActionGroupReturningValue = $I->return($grabProducts2ExtendedActionGroupReturningValue); // stepKey: returnProducts2ExtendedActionGroupReturningValue + $I->comment("Exiting Action Group [extendedActionGroupReturningValue] ExtendedActionGroupReturningValueActionGroup"); + $I->comment("Entering Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + $I->see($extendedActionGroupReturningValue, "#element .{$extendedActionGroupReturningValue}"); // stepKey: see1ActionGroupWithStringUsage1 + $I->comment("Exiting Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + } +} diff --git a/dev/tests/verification/Resources/MergedActionGroupReturningValueTest.txt b/dev/tests/verification/Resources/MergedActionGroupReturningValueTest.txt new file mode 100644 index 000000000..a4689779b --- /dev/null +++ b/dev/tests/verification/Resources/MergedActionGroupReturningValueTest.txt @@ -0,0 +1,77 @@ +Test filesverification/TestModule/Test/MergeFunctionalTest/MergedActionGroupReturningValueTest.xml
") + */ +class MergedActionGroupReturningValueTestCest +{ + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _before(AcceptanceTester $I) + { + $I->createEntity("createPersonParam", "hook", "ReplacementPerson", [], []); // stepKey: createPersonParam + $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); + $I->fillField("#foo", "myData1"); // stepKey: fillField1BeforeGroup + $I->fillField("#bar", "myData2"); // stepKey: fillField2BeforeGroup + $I->comment("Exiting Action Group [beforeGroup] FunctionalActionGroup"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _after(AcceptanceTester $I) + { + $I->comment("Entering Action Group [afterGroup] FunctionalActionGroup"); + $I->fillField("#foo", "myData1"); // stepKey: fillField1AfterGroup + $I->fillField("#bar", "myData2"); // stepKey: fillField2AfterGroup + $I->comment("Exiting Action Group [afterGroup] FunctionalActionGroup"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _failed(AcceptanceTester $I) + { + $I->saveScreenshot(); // stepKey: saveScreenshot + } + + /** + * @Severity(level = SeverityLevel::CRITICAL) + * @Features({"TestModule"}) + * @Stories({"MQE-433"}) + * @Parameter(name = "AcceptanceTester", value="$I") + * @param AcceptanceTester $I + * @return void + * @throws \Exception + */ + public function MergedActionGroupReturningValueTest(AcceptanceTester $I) + { + $I->amOnPage("/someUrl"); // stepKey: step1 + $I->comment("Entering Action Group [actionGroupWithReturnValue1] MergeActionGroupReturningValueActionGroup"); + $I->amOnPage("/Jane/Dane.html"); // stepKey: amOnPage1ActionGroupWithReturnValue1 + $I->click(".merge .Jane"); // stepKey: myMergedClickActionGroupWithReturnValue1 + $grabMultiple1ActionGroupWithReturnValue1 = $I->grabMultiple("#foo"); // stepKey: grabMultiple1ActionGroupWithReturnValue1 + $actionGroupWithReturnValue1 = $I->return($grabMultiple1ActionGroupWithReturnValue1); // stepKey: returnValueActionGroupWithReturnValue1 + $I->comment("Exiting Action Group [actionGroupWithReturnValue1] MergeActionGroupReturningValueActionGroup"); + $I->comment("Entering Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + $I->see($actionGroupWithReturnValue1, "#element .{$actionGroupWithReturnValue1}"); // stepKey: see1ActionGroupWithStringUsage1 + $I->comment("Exiting Action Group [actionGroupWithStringUsage1] actionGroupWithStringUsage"); + } +} diff --git a/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ActionGroupReturningValueActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ActionGroupReturningValueActionGroup.xml new file mode 100644 index 000000000..ddb93c0c1 --- /dev/null +++ b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ActionGroupReturningValueActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + + + + {{count}} + grabProducts1 + + + + diff --git a/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ExtendedActionGroupReturningValueActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ExtendedActionGroupReturningValueActionGroup.xml new file mode 100644 index 000000000..18933a2f2 --- /dev/null +++ b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup/ExtendedActionGroupReturningValueActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + + + + {{otherCount}} + grabProducts2 + + + + diff --git a/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml new file mode 100644 index 000000000..83afbce0c --- /dev/null +++ b/dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/dev/tests/verification/TestModule/ActionGroup/MergeFunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/MergeFunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml new file mode 100644 index 000000000..d952fdddf --- /dev/null +++ b/dev/tests/verification/TestModule/ActionGroup/MergeFunctionalActionGroup/MergeActionGroupReturningValueActionGroup.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedActionGroupReturningValueTest.xml b/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedActionGroupReturningValueTest.xml new file mode 100644 index 000000000..68042344c --- /dev/null +++ b/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedActionGroupReturningValueTest.xml @@ -0,0 +1,22 @@ + + + + + + + + </annotations> + <actionGroup ref="ActionGroupReturningValueActionGroup" stepKey="actionGroupReturningValue"> + <argument name="count" value="99"/> + </actionGroup> + <actionGroup ref="actionGroupWithStringUsage" stepKey="actionGroupWithStringUsage1"> + <argument name="someArgument" value="{$actionGroupReturningValue}"/> + </actionGroup> + </test> +</tests> diff --git a/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedChildActionGroupReturningValueTest.xml b/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedChildActionGroupReturningValueTest.xml new file mode 100644 index 000000000..ecd46c3c4 --- /dev/null +++ b/dev/tests/verification/TestModule/Test/ActionGroupTest/ExtendedChildActionGroupReturningValueTest.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="ExtendedChildActionGroupReturningValueTest"> + <annotations> + <severity value="CRITICAL"/> + <title value="Extended Child ActionGroup Returning Value Test"/> + </annotations> + <actionGroup ref="ExtendedActionGroupReturningValueActionGroup" stepKey="extendedActionGroupReturningValue"> + <argument name="count" value="99"/> + <argument name="otherCount" value="8000"/> + </actionGroup> + <actionGroup ref="actionGroupWithStringUsage" stepKey="actionGroupWithStringUsage1"> + <argument name="someArgument" value="{$extendedActionGroupReturningValue}"/> + </actionGroup> + </test> +</tests> diff --git a/dev/tests/verification/TestModule/Test/MergeFunctionalTest/MergedActionGroupReturningValueTest.xml b/dev/tests/verification/TestModule/Test/MergeFunctionalTest/MergedActionGroupReturningValueTest.xml new file mode 100644 index 000000000..baf7c0ded --- /dev/null +++ b/dev/tests/verification/TestModule/Test/MergeFunctionalTest/MergedActionGroupReturningValueTest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="MergedActionGroupReturningValueTest"> + <annotations> + <severity value="CRITICAL"/> + <group value="functional"/> + <features value="Action Group Functional Cest"/> + <stories value="MQE-433"/> + </annotations> + <before> + <createData entity="ReplacementPerson" stepKey="createPersonParam"/> + <actionGroup ref="FunctionalActionGroup" stepKey="beforeGroup"/> + </before> + <amOnPage url="/someUrl" stepKey="step1"/> + <actionGroup ref="MergeActionGroupReturningValueActionGroup" stepKey="actionGroupWithReturnValue1"> + <argument name="myArg" value="DefaultPerson"/> + </actionGroup> + <actionGroup ref="actionGroupWithStringUsage" stepKey="actionGroupWithStringUsage1"> + <argument name="someArgument" value="{$actionGroupWithReturnValue1}"/> + </actionGroup> + <after> + <actionGroup ref="FunctionalActionGroup" stepKey="afterGroup"/> + </after> + </test> +</tests> diff --git a/dev/tests/verification/Tests/ActionGroupWithReturnGenerationTest.php b/dev/tests/verification/Tests/ActionGroupWithReturnGenerationTest.php new file mode 100644 index 000000000..e369a797d --- /dev/null +++ b/dev/tests/verification/Tests/ActionGroupWithReturnGenerationTest.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace tests\verification\Tests; + +use tests\util\MftfTestCase; + +class ActionGroupWithReturnGenerationTest extends MftfTestCase +{ + /** + * Test generation of a test referencing an action group that returns a value. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testActionGroupReturningValue() + { + $this->generateAndCompareTest('ActionGroupReturningValueTest'); + } + /** + * Test generation of a test referencing a merged action group that returns a value. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testMergedActionGroupReturningValue() + { + $this->generateAndCompareTest('MergedActionGroupReturningValueTest'); + } + /** + * Test generation of a test referencing an extended action group that returns a value. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testExtendedActionGroupReturningValue() + { + $this->generateAndCompareTest('ExtendedActionGroupReturningValueTest'); + } + /** + * Test generation of a test referencing an extending child action group that returns a value. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testExtendedChildActionGroupReturningValue() + { + $this->generateAndCompareTest('ExtendedChildActionGroupReturningValueTest'); + } +} diff --git a/docs/data.md b/docs/data.md index 8b0a86e3d..d642763d0 100644 --- a/docs/data.md +++ b/docs/data.md @@ -78,6 +78,8 @@ A test can also reference data that was returned as a result of [test actions][] Further in the test, the data grabbed by the `someSelector` selector can be referenced using the `stepKey` value. In this case, it is `grabStepKey`. +The `stepKey` value can only be referenced within the test scope that it is defined in (`test`, `before/after`). + The following example shows the usage of `grabValueFrom` in testing, where the returned value is used by action's `stepKey`: ```xml diff --git a/docs/test/action-groups.md b/docs/test/action-groups.md index 80caf0883..05adf795e 100644 --- a/docs/test/action-groups.md +++ b/docs/test/action-groups.md @@ -180,33 +180,33 @@ MFTF resolves `{{myCustomEntity.field1}}` the same as it would in a `selector` o </actionGroup> ``` -## Returning a value +## Return a value -Action groups can return a value using `<return>` action. +Action groups can return a value using a `return` tag. ```xml <actionGroup name="GetOrderIdActionGroup"> <seeElement selector="{{CheckoutSuccessMainSection.orderLink}}" stepKey="assertOrderLink"/> <grabTextFrom selector="{{CheckoutSuccessMainSection.orderLink}}" stepKey="orderId"/> - <return value="{$grabTextFrom1}" stepKey="returnOrderId"/> + <return value="{$orderId}" stepKey="returnOrderId"/> </actionGroup> ``` -This value can be accessed as below: - -1. Reference `GetOrderIdActionGroup` action group: +The value returned can be accessed in later steps using action group step key `{$getOrderId}`. ```xml -<!-- Open Orders Index Page --> <actionGroup ref="GetOrderIdActionGroup" stepKey="getOrderId"/> -``` - -1. To use the value returned in another action group, using action group stepKey {getOrderId}: -```xml <!--Filter the Order using Order ID --> <actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrderGridById"> <argument name="orderId" value="{$getOrderId}"/> </actionGroup> ``` +### Convention to return a value + +The following conventions apply to action groups returning a value: +- Only action groups can return value. Use of `return` tag is dis-allowed in tests and suites. +- An action group does not support multiple `return` tags. +- For [merging action groups](../merging.md#merge-action-groups), `return` is allowed only in one of the merging action groups. +- Value returned by an action group can only be referenced within the scope that the action group is defined in (`test`, `before/after`). ## Optimizing action group structures diff --git a/docs/test/actions.md b/docs/test/actions.md index 1bfffe748..562f6e8ff 100644 --- a/docs/test/actions.md +++ b/docs/test/actions.md @@ -1243,30 +1243,17 @@ To access this value, use `{$grabInputName}` in later actions. --> ### return -Allows action group to return a value. Value can be then accessed in the test using the action group stepKey. +Specifies what value is returned by an action group. The value can be then accessed in later steps using the action group stepKey. See [Action groups returning a value](./action-groups.md#return-a-value) for usage information. Attribute|Type|Use|Description ---|---|---|--- -`value`|string|required| value returned by actionGroup. +`value`|string|required| value returned by action group. `stepKey`|string|required| A unique identifier of the action. #### Example - -```xml -<!-- Returns a value to the action group's step key. --> -<actionGroup name="ActionGroupWithReturnValue"> - <grabTextFrom selector="#foo" stepKey="grabTextFrom1"/> - <return value="{$grabTextFrom1}" stepKey="returnValue"/> -</actionGroup> -``` ```xml -<!-- To access this value, use `{$actionGroupWithReturnValue}` in later actions or action groups. --> -<test name="ActionGroupReturningValueTest"> - <actionGroup ref="ActionGroupWithReturnValue" stepKey="actionGroupWithReturnValue"/> - <actionGroup ref="ActionGroupWithStringUsage" stepKey="actionGroupWithStringUsage"> - <argument name="someArgument" value="{$actionGroupWithReturnValue}"/> - </actionGroup> -</test> +<!-- Returns value of $grabInputName to the calling +<return value="{$grabInputName}" stepKey="returnInputName"/> ``` ### loadSessionSnapshot From 669f5ee6acd508ecc283d20dc99f9b76ac3d47da Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan <sunnikri@adobe.com> Date: Mon, 20 Jul 2020 14:07:14 -0500 Subject: [PATCH 3/4] MQE-1886: Ability to use grab data between ActionGroups added functional test. --- .../ActionGroup/ReturnValueActionGroup.xml | 15 +++++++++++++++ .../tests/MFTF/DevDocs/Test/DevDocsTest.xml | 6 ++++++ .../Tests/ActionGroupGenerationTest.php | 11 ----------- .../Test/etc/Actions/customActions.xsd | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml diff --git a/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml b/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml new file mode 100644 index 000000000..98bc6128b --- /dev/null +++ b/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="ReturnValueActionGroup"> + <comment userInput="Action group to demonstrate returning values." stepKey="comment"/> + <executeJS function="return 'test'" stepKey="testVariable"/> + <return value="{$testVariable}" stepKey="returnVar"/> + </actionGroup> +</actionGroups> diff --git a/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml b/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml index bda1cfb57..0dc18f3cd 100644 --- a/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml +++ b/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml @@ -51,5 +51,11 @@ <actualResult type="array">{{ExtendedMessageData.numbers}}</actualResult> <expectedResult type="array">["Something New", "0", "1", "2", "3", "TESTING CASE"]</expectedResult> </assertEqualsCanonicalizing> + + <actionGroup ref="ReturnValueActionGroup" stepKey="actionGroupValue"/> + <assertEquals stepKey="assertActionGroupValue"> + <expectedResult type="variable">actionGroupValue</expectedResult> + <actualResult type="string">test</actualResult> + </assertEquals> </test> </tests> diff --git a/dev/tests/verification/Tests/ActionGroupGenerationTest.php b/dev/tests/verification/Tests/ActionGroupGenerationTest.php index 4b888407f..3f9412aec 100644 --- a/dev/tests/verification/Tests/ActionGroupGenerationTest.php +++ b/dev/tests/verification/Tests/ActionGroupGenerationTest.php @@ -228,15 +228,4 @@ public function testActionGroupWithActionStepKeyReferencesInSelectors() { $this->generateAndCompareTest('ActionGroupWithParameterizedElementsWithStepKeyReferences'); } - - /** - * Test generation of a test referencing an action group that returns a value. - * - * @throws \Exception - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException - */ - public function testActionGroupReturningValue() - { - $this->generateAndCompareTest('ActionGroupReturningValueTest'); - } } diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd index 64fbaeaed..b1d6e1b02 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd @@ -363,7 +363,7 @@ <xs:attribute name="value" use="required" type="xs:string"> <xs:annotation> <xs:documentation> - Value to be returned. + Value or variable to be returned. </xs:documentation> </xs:annotation> </xs:attribute> From e01a26f0fa2a2dab4d8d88fed7a0804df8f70c10 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan <sunnikri@adobe.com> Date: Tue, 21 Jul 2020 16:33:57 -0500 Subject: [PATCH 4/4] MQE-1886: Ability to use grab data between ActionGroups added functional test. Removed functional test for return. --- .../ActionGroup/ReturnValueActionGroup.xml | 15 --------------- .../tests/MFTF/DevDocs/Test/DevDocsTest.xml | 6 ------ 2 files changed, 21 deletions(-) delete mode 100644 dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml diff --git a/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml b/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml deleted file mode 100644 index 98bc6128b..000000000 --- a/dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/ReturnValueActionGroup.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ ---> -<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <actionGroup name="ReturnValueActionGroup"> - <comment userInput="Action group to demonstrate returning values." stepKey="comment"/> - <executeJS function="return 'test'" stepKey="testVariable"/> - <return value="{$testVariable}" stepKey="returnVar"/> - </actionGroup> -</actionGroups> diff --git a/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml b/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml index 0dc18f3cd..bda1cfb57 100644 --- a/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml +++ b/dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml @@ -51,11 +51,5 @@ <actualResult type="array">{{ExtendedMessageData.numbers}}</actualResult> <expectedResult type="array">["Something New", "0", "1", "2", "3", "TESTING CASE"]</expectedResult> </assertEqualsCanonicalizing> - - <actionGroup ref="ReturnValueActionGroup" stepKey="actionGroupValue"/> - <assertEquals stepKey="assertActionGroupValue"> - <expectedResult type="variable">actionGroupValue</expectedResult> - <actualResult type="string">test</actualResult> - </assertEquals> </test> </tests>