Skip to content

Commit 4ec6362

Browse files
authored
MQE-697: Grab test actions's results cannot be used in action-groups
- Added $actionOrigin to actionObject, an array used to keep track of an action's origin. - Replacement of actionGroup key is done at TestGenerator level.
1 parent df1b230 commit 4ec6362

File tree

10 files changed

+210
-74
lines changed

10 files changed

+210
-74
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionGroupObjectTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class ActionGroupObjectTest extends TestCase
2323
{
24-
const ACTION_GROUP_MERGE_KEY = 'testKey';
24+
const ACTION_GROUP_MERGE_KEY = 'TestKey';
2525

2626
/**
2727
* Tests a string literal in an action group
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_generated\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use \Codeception\Util\Locator;
9+
use Yandex\Allure\Adapter\Annotation\Features;
10+
use Yandex\Allure\Adapter\Annotation\Stories;
11+
use Yandex\Allure\Adapter\Annotation\Title;
12+
use Yandex\Allure\Adapter\Annotation\Description;
13+
use Yandex\Allure\Adapter\Annotation\Parameter;
14+
use Yandex\Allure\Adapter\Annotation\Severity;
15+
use Yandex\Allure\Adapter\Model\SeverityLevel;
16+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
17+
18+
/**
19+
*/
20+
class ActionGroupWithStepKeyReferencesCest
21+
{
22+
/**
23+
* @Parameter(name = "AcceptanceTester", value="$I")
24+
* @param AcceptanceTester $I
25+
* @return void
26+
* @throws \Exception
27+
*/
28+
public function ActionGroupWithStepKeyReferences(AcceptanceTester $I)
29+
{
30+
$I->amGoingTo("create entity that has the stepKey: createSimpleDataActionGroup");
31+
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
32+
$createSimpleDataActionGroup = new DataPersistenceHandler($simpleData, []);
33+
$createSimpleDataActionGroup->createEntity();
34+
$grabTextDataActionGroup = $I->grabTextFrom(".class");
35+
$I->fillField(".{$grabTextDataActionGroup}", $createSimpleDataActionGroup->getCreatedDataByName('field'));
36+
}
37+
}

dev/tests/verification/Resources/BasicFunctionalTest.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class BasicFunctionalTestCest
9797
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector");
9898
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector");
9999
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector");
100-
$magentoCli1 = $I->executeMagentoCLICommand("maintenance:enable");
100+
$magentoCli1 = $I->magentoCLI("maintenance:enable");
101101
$I->comment($magentoCli1);
102102
$I->makeScreenshot("screenShotInput");
103103
$I->maximizeWindow();

dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt

+12-12
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ class PersistenceCustomFieldsTestCest
6868
$UniquePerson = DataObjectHandler::getInstance()->getObject("UniquePerson");
6969
$createdData3 = new DataPersistenceHandler($UniquePerson, [$createdData], $createdData3Fields);
7070
$createdData3->createEntity();
71-
$createDataAG1createdAGFields['firstname'] = "string1";
72-
$I->amGoingTo("create entity that has the stepKey: createDataAG1createdAG");
71+
$createDataAG1CreatedAGFields['firstname'] = "string1";
72+
$I->amGoingTo("create entity that has the stepKey: createDataAG1CreatedAG");
7373
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
74-
$createDataAG1createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG1createdAGFields);
75-
$createDataAG1createdAG->createEntity();
76-
$createDataAG2createdAGFields['firstname'] = "Jane";
77-
$I->amGoingTo("create entity that has the stepKey: createDataAG2createdAG");
74+
$createDataAG1CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG1CreatedAGFields);
75+
$createDataAG1CreatedAG->createEntity();
76+
$createDataAG2CreatedAGFields['firstname'] = "Jane";
77+
$I->amGoingTo("create entity that has the stepKey: createDataAG2CreatedAG");
7878
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
79-
$createDataAG2createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG2createdAGFields);
80-
$createDataAG2createdAG->createEntity();
81-
$createDataAG3createdAGFields['firstname'] = $createdData3->getCreatedDataByName('firstname');
82-
$I->amGoingTo("create entity that has the stepKey: createDataAG3createdAG");
79+
$createDataAG2CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG2CreatedAGFields);
80+
$createDataAG2CreatedAG->createEntity();
81+
$createDataAG3CreatedAGFields['firstname'] = $createdData3->getCreatedDataByName('firstname');
82+
$I->amGoingTo("create entity that has the stepKey: createDataAG3CreatedAG");
8383
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
84-
$createDataAG3createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG3createdAGFields);
85-
$createDataAG3createdAG->createEntity();
84+
$createDataAG3CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG3CreatedAGFields);
85+
$createDataAG3CreatedAG->createEntity();
8686
}
8787
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@
4545
<seeElement stepKey="see1" selector="{{SampleSection.simpleElement}}"/>
4646
<seeElement stepKey="see2" selector="{{SampleSection.simpleElementOneParam(simple.firstname)}}"/>
4747
</actionGroup>
48+
<actionGroup name="FunctionActionGroupWithStepKeyReferences">
49+
<createData entity="simpleData" stepKey="createSimpleData"/>
50+
<grabTextFrom selector=".class" stepKey="grabTextData"/>
51+
<fillField stepKey="fill1" selector=".{$grabTextData}" userInput="$createSimpleData.field$"/>
52+
</actionGroup>
4853
</actionGroups>

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

+4
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,8 @@
110110
</annotations>
111111
<actionGroup ref="actionGroupWithStringUsage" stepKey="actionGroup"/>
112112
</test>
113+
114+
<test name="ActionGroupWithStepKeyReferences">
115+
<actionGroup ref="FunctionActionGroupWithStepKeyReferences" stepKey="actionGroup"/>
116+
</test>
113117
</tests>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ public function testActionGroupWithSimpleDataUsageFromDefaultArgument()
9696
{
9797
$this->generateAndCompareTest('ActionGroupWithSimpleDataUsageFromDefaultArgument');
9898
}
99+
100+
/**
101+
* Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData)
102+
*
103+
* @throws \Exception
104+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
105+
*/
106+
public function testActionGroupWithStepKeyReferences()
107+
{
108+
$this->generateAndCompareTest('ActionGroupWithStepKeyReferences');
109+
}
99110
}

src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
class ActionGroupObject
1717
{
18+
const ACTION_GROUP_ORIGIN_NAME = "actionGroupName";
19+
const ACTION_GROUP_ORIGIN_TEST_REF = "testInvocationRef";
20+
1821
/**
1922
* Array of variable-enabled attributes.
2023
* @var array
@@ -153,12 +156,14 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
153156

154157
// we append the action reference key to any linked action and the action's merge key as the user might
155158
// use this action group multiple times in the same test.
156-
$resolvedActions[$action->getStepKey() . $actionReferenceKey] = new ActionObject(
157-
$action->getStepKey() . $actionReferenceKey,
159+
$resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject(
160+
$action->getStepKey() . ucfirst($actionReferenceKey),
158161
$action->getType(),
159162
array_merge($action->getCustomActionAttributes(), $newActionAttributes),
160-
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . $actionReferenceKey,
161-
$action->getOrderOffset()
163+
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
164+
$action->getOrderOffset(),
165+
[self::ACTION_GROUP_ORIGIN_NAME => $this->name,
166+
self::ACTION_GROUP_ORIGIN_TEST_REF => $actionReferenceKey]
162167
);
163168
}
164169

@@ -307,6 +312,19 @@ private function replacePersistedArgument($replacement, $attributeValue, $fullVa
307312
return $newAttributeValue;
308313
}
309314

315+
/**
316+
* Finds and returns all original stepkeys of actions in actionGroup.
317+
* @return string[]
318+
*/
319+
public function extractStepKeys()
320+
{
321+
$originalKeys = [];
322+
foreach ($this->parsedActions as $action) {
323+
$originalKeys[] = $action->getStepKey();
324+
}
325+
return $originalKeys;
326+
}
327+
310328
/**
311329
* Searches through ActionGroupObject's arguments and returns first argument wi
312330
* @param string $name

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class ActionObject
9292
*/
9393
private $timeout;
9494

95+
/**
96+
* An array with items containing information of the origin of this action.
97+
*
98+
* @var array
99+
*/
100+
private $actionOrigin = [];
101+
95102
/**
96103
* ActionObject constructor.
97104
*
@@ -100,18 +107,21 @@ class ActionObject
100107
* @param array $actionAttributes
101108
* @param string|null $linkedAction
102109
* @param string $order
110+
* @param array $actionOrigin
103111
*/
104112
public function __construct(
105113
$stepKey,
106114
$type,
107115
$actionAttributes,
108116
$linkedAction = null,
109-
$order = ActionObject::MERGE_ACTION_ORDER_BEFORE
117+
$order = ActionObject::MERGE_ACTION_ORDER_BEFORE,
118+
$actionOrigin = null
110119
) {
111120
$this->stepKey = $stepKey;
112121
$this->type = $type;
113122
$this->actionAttributes = $actionAttributes;
114123
$this->linkedAction = $linkedAction;
124+
$this->actionOrigin = $actionOrigin;
115125

116126
if ($order == ActionObject::MERGE_ACTION_ORDER_AFTER) {
117127
$this->orderOffset = 1;
@@ -138,6 +148,16 @@ public function getType()
138148
return $this->type;
139149
}
140150

151+
/**
152+
* Getter for actionOrigin
153+
*
154+
* @return string
155+
*/
156+
public function getActionOrigin()
157+
{
158+
return $this->actionOrigin;
159+
}
160+
141161
/**
142162
* This function returns an array of action attributes mapped by key. For example
143163
* the tag <seeNumberOfElements selector="value1" expected="value2" stepKey=""/> has 3 attributes,

0 commit comments

Comments
 (0)