Skip to content

Commit 12964bb

Browse files
committed
MQE-1964: MFTF Helper - Implementation
- addressed review comments
1 parent 4458f0a commit 12964bb

File tree

7 files changed

+42
-22
lines changed

7 files changed

+42
-22
lines changed

dev/tests/functional/tests/MFTF/DevDocs/ActionGroup/DeprecatedCommentActionGroup.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
1010
<actionGroup name="DeprecatedCommentActionGroup" deprecated="This Action Group is outdated and will be deleted next release.">
11-
<arguments>
12-
<argument name="test" type="string" />
13-
</arguments>
1411
<comment userInput="Action group to demonstrate deprecation notices." stepKey="comment" />
15-
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="goTo" stepKey="custobhhmHelper">
16-
<argument name="test">{{contentSection.pageIntro}}</argument>
17-
<argument name="module">['{{test}}', 'Bla']</argument>
18-
<argument name="url">{{test}}</argument>
19-
</helper>
20-
2112
</actionGroup>
2213
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="HelperActionGroup">
11+
<arguments>
12+
<argument name="test" type="string" />
13+
</arguments>
14+
<comment userInput="Action group to demonstrate helper functionality available from action groups." stepKey="comment" />
15+
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="goTo" stepKey="customHelper">
16+
<argument name="test">{{contentSection.parametrizedSelector(test)}}</argument>
17+
<argument name="module">['{{test}}', 'Bla']</argument>
18+
<argument name="url">{{test}}</argument>
19+
</helper>
20+
</actionGroup>
21+
</actionGroups>

dev/tests/functional/tests/MFTF/DevDocs/Helper/CustomHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class CustomHelper extends Helper
1414
* Custom helper.
1515
*
1616
* @param string $url
17-
* @param float $test
17+
* @param mixed $test
1818
* @param array $module
1919
* @param null $superBla
20-
* @param string $bla
20+
* @param mixed $bla
2121
* @param array $arraysomething
2222
* @return void
2323
*/
@@ -27,14 +27,14 @@ public function goTo(
2727
array $module = [],
2828
$superBla = null,
2929
$bla = 'blaValue',
30-
array $arraysomething = []
30+
array $arraysomething = ['key' => 'value', 'test']
3131
) {
3232
print('Hello, this is custom helper which gives an ability to write custom solutions without usage of <executeInSelenium /> and <performOn /> actions.');
3333
print('string $url = ' . $url . PHP_EOL);
3434
print('$test = ' . $test . PHP_EOL);
3535
print('array $module = [' . implode(', ', $module) . ']' . PHP_EOL);
3636
print('$superBla = ' . $superBla . PHP_EOL);
37-
print('$bla = ' . $url . PHP_EOL);
37+
print('$bla = ' . $bla . PHP_EOL);
3838
print('array $arraysomething = [' . implode(', ', $arraysomething) . ']' . PHP_EOL);
3939
}
4040
}

dev/tests/functional/tests/MFTF/DevDocs/Section/ContentSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="contentSection">
1212
<element name="pageIntro" type="text" selector=".page-intro"/>
13+
<element name="parametrizedSelector" type="text" selector=".page-intro > {{justToProofItWorks}}" parameterized="true"/>
1314
<element name="deprecatedPageIntro" type="text" selector=".page-intro-old" deprecated="New element was introduced. Please use 'contentSection.pageIntro'"/>
1415
</section>
1516
</sections>

dev/tests/functional/tests/MFTF/DevDocs/Test/DeprecatedDevDocsTest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
<!-- Open MFTF DevDocs Page -->
2323
<amOnPage stepKey="openMFTFDevDocPage" url="{{DeprecatedMFTFDocPage.url}}" />
2424
<see stepKey="verifyPageIntroText" selector="{{DeprecatedContentSection.pageIntro}}" userInput="{{DeprecatedMessageData.message}}" />
25-
<actionGroup ref="DeprecatedCommentActionGroup" stepKey="commentActionGroup">
26-
<argument name="test" value="{{DeprecatedContentSection.pageIntro}}" />
27-
</actionGroup>
25+
<actionGroup ref="DeprecatedCommentActionGroup" stepKey="commentActionGroup"/>
2826
</test>
2927
</tests>

dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
<argument name="url">{{MFTFDocPage.url}}</argument>
2929
</helper>
3030

31-
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="goTo" stepKey="custobhhmHelper">
31+
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="goTo" stepKey="customHelperWithArrayParametrized">
3232
<argument name="test">{{contentSection.pageIntro}}</argument>
3333
<argument name="module">['{{DeprecatedContentSection.pageIntro}}', 'Bla']</argument>
3434
<argument name="url">{{DeprecatedMFTFDocPage.url}}</argument>
3535
</helper>
36+
37+
<actionGroup ref="HelperActionGroup" stepKey="actionGroupWithCustomHelper">
38+
<argument name="test" value="{{HelperData.entityField}}" />
39+
</actionGroup>
3640
</test>
3741
</tests>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,21 +825,26 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
825825
$customActionAttributes['method']
826826
);
827827
$typesToQuote = ['string', 'float'];
828+
$errors = [];
828829
foreach ($parameters as $parameter) {
829830
if (isset($customActionAttributes[$parameter['variableName']])) {
830831
$value = $customActionAttributes[$parameter['variableName']];
831832
$arguments[] = $this->addUniquenessFunctionCall(
832833
$value,
833834
in_array($parameter['type'], $typesToQuote) || $parameter['type'] === null
834835
);
835-
} elseif (!$parameter['isOptional']) {
836-
throw new TestFrameworkException(
837-
'Argument \'' . $parameter['variableName'] . '\' for method '
836+
} elseif ($parameter['isOptional']) {
837+
$value = $parameter['optionalValue'];
838+
$arguments[] = str_replace(PHP_EOL, '' , var_export($value, true));
839+
} else {
840+
$errors[] = 'Argument \'' . $parameter['variableName'] . '\' for method '
838841
. $customActionAttributes['class'] . '::' . $customActionAttributes['method']
839-
. ' is not found.'
840-
);
842+
. ' is not found.';
841843
}
842844
}
845+
if (!empty($errors)) {
846+
throw new TestFrameworkException(implode(PHP_EOL, $errors));
847+
}
843848
$testSteps .= sprintf(
844849
"\t\t$%s->comment('[%s] %s()');" . PHP_EOL,
845850
$actor,

0 commit comments

Comments
 (0)