Skip to content

Commit 36c21d3

Browse files
committed
MQE-1373: Cannot Use Data Returned By Test Actions As Substitutable Value Inside Parameterized Selector From Within Action Group
to replace custom field key in create data added verification test + comments
1 parent 932c435 commit 36c21d3

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
7+
use \Codeception\Util\Locator;
8+
use Yandex\Allure\Adapter\Annotation\Features;
9+
use Yandex\Allure\Adapter\Annotation\Stories;
10+
use Yandex\Allure\Adapter\Annotation\Title;
11+
use Yandex\Allure\Adapter\Annotation\Description;
12+
use Yandex\Allure\Adapter\Annotation\Parameter;
13+
use Yandex\Allure\Adapter\Annotation\Severity;
14+
use Yandex\Allure\Adapter\Model\SeverityLevel;
15+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
16+
17+
/**
18+
*/
19+
class ActionGroupWithParameterizedElementsWithStepKeyReferencesCest
20+
{
21+
/**
22+
* @Features({"TestModule"})
23+
* @Parameter(name = "AcceptanceTester", value="$I")
24+
* @param AcceptanceTester $I
25+
* @return void
26+
* @throws \Exception
27+
*/
28+
public function ActionGroupWithParameterizedElementsWithStepKeyReferences(AcceptanceTester $I)
29+
{
30+
$I->comment("Entering Action Group [actionGroup] actionGroupWithParametrizedSelectors");
31+
$testVariableActionGroup = $I->executeJS("return 1"); // stepKey: testVariableActionGroup
32+
$testVariable2ActionGroup = $I->executeJS("return 'test'"); // stepKey: testVariable2ActionGroup
33+
$I->comment("[createSimpleDataActionGroup] create 'simpleData' entity");
34+
PersistedObjectHandler::getInstance()->createEntity(
35+
"createSimpleDataActionGroup",
36+
"test",
37+
"simpleData",
38+
[],
39+
[]
40+
);
41+
42+
$I->click("#{$testVariable2ActionGroup} .John"); // stepKey: click1ActionGroup
43+
$I->click("#Doe-" . msq("simpleParamData") . "prename .{$testVariableActionGroup}"); // stepKey: click2ActionGroup
44+
$I->seeElement("//div[@name='Tiberius'][@class={$testVariableActionGroup}][@data-element='{$testVariable2ActionGroup}'][" . PersistedObjectHandler::getInstance()->retrieveEntityField('createSimpleData', 'name', 'test') . "]"); // stepKey: see1ActionGroup
45+
$I->comment("Exiting Action Group [actionGroup] actionGroupWithParametrizedSelectors");
46+
}
47+
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,16 @@
9191
</arguments>
9292
<executeJS function="{{section.oneParamElement('full-width')}}" stepKey="keyone"/>
9393
</actionGroup>
94+
<actionGroup name="actionGroupWithParametrizedSelectors">
95+
<arguments>
96+
<argument name="param" type="entity"/>
97+
<argument name="param2" type="entity" defaultValue="simpleParamData"/>
98+
</arguments>
99+
<executeJS function="return 1" stepKey="testVariable"/>
100+
<executeJS function="return 'test'" stepKey="testVariable2"/>
101+
<createData entity="simpleData" stepKey="createSimpleData"/>
102+
<click selector="{{SampleSection.twoParamElement({$testVariable2}, param.firstname)}}" stepKey="click1"/>
103+
<click selector="{{SampleSection.threeParamElement(param.lastname, param2.uniqueNamePre, {$testVariable})}}" stepKey="click2"/>
104+
<seeElement selector="{{SampleSection.fourParamElement(param.middlename, {$testVariable}, {$testVariable2}, $$createSimpleData.name$$)}}" stepKey="see1"/>
105+
</actionGroup>
94106
</actionGroups>

dev/tests/verification/TestModule/Section/SampleSection.xml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<element name="oneParamElement" type="button" selector="#element .{{var1}}" parameterized="true"/>
1616
<element name="twoParamElement" type="button" selector="#{{var1}} .{{var2}}" parameterized="true"/>
1717
<element name="threeParamElement" type="button" selector="#{{var1}}-{{var2}} .{{var3}}" parameterized="true"/>
18+
<element name="fourParamElement" type="input" selector="//div[@name='{{arg1}}'][@class={{arg2}}][@data-element='{{arg3}}'][{{arg4}}]" parameterized="true"/>
1819
<element name="threeOneDuplicateParamElement" type="button" selector="#{{var1}}-{{var2}} .{{var1}} [{{var3}}]" parameterized="true"/>
1920
<element name="timeoutElement" type="button" selector="#foo" timeout="30"/>
2021
<element name="mergeElement" type="button" selector="#unMerge"/>

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

+7
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,11 @@
171171
<argument name="section" value="SampleSection"/>
172172
</actionGroup>
173173
</test>
174+
175+
<test name="ActionGroupWithParameterizedElementsWithStepKeyReferences">
176+
<actionGroup ref="actionGroupWithParametrizedSelectors" stepKey="actionGroup">
177+
<argument name="param" value="simpleData"/>
178+
<argument name="param2" value="simpleParamData"/>
179+
</actionGroup>
180+
</test>
174181
</tests>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,15 @@ public function testActionGroupWithXmlComments()
217217
{
218218
$this->generateAndCompareTest('XmlCommentedActionGroupTest');
219219
}
220+
221+
/**
222+
* Test generation of a test referencing an action group with selectors referencing stepKeys.
223+
*
224+
* @throws \Exception
225+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
226+
*/
227+
public function testActionGroupWithActionStepKeyReferencesInSelectors()
228+
{
229+
$this->generateAndCompareTest('ActionGroupWithParameterizedElementsWithStepKeyReferences');
230+
}
220231
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+2
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,8 @@ private function resolveStepKeyReferences($input, $actionGroupOrigin, $matchAll
14821482
$persistedVarRefInvoked = "PersistedObjectHandler::getInstance()->retrieveEntityField('"
14831483
. $stepKey . $testInvocationKey . "', 'field', 'test')";
14841484

1485+
// only replace when whole word matches exactly
1486+
// e.g. testVar => $testVar but not $testVar2
14851487
if (strpos($output, $stepKeyVarRef) !== false) {
14861488
$output = preg_replace('/\B\\' .$stepKeyVarRef. '\b/', $stepKeyVarRef . $testInvocationKey, $output);
14871489
}

0 commit comments

Comments
 (0)