Skip to content

Commit 9c7bf5f

Browse files
committed
MQE-1234: Allow XML Parser to read XML comment into comment action
1 parent 17b8b9d commit 9c7bf5f

File tree

8 files changed

+31
-4
lines changed

8 files changed

+31
-4
lines changed

dev/tests/functional/tests/MFTF/DevDocs/Page/MFTFDocPage.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../../../src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
11-
<page name="MFTFDocPage" url="guides/v2.2/magento-functional-testing-framework/release-2/introduction.html" area="storefront" module="MFTF_DevDocs">
11+
<page name="MFTFDocPage" url="mftf/docs/introduction.html" area="storefront" module="MFTF_DevDocs">
1212
<section name="contentSection" />
1313
</page>
1414
</pages>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
1111
<test name="DevDocsTest">
1212
<annotations>
13+
<!-- Hwello -->
1314
<features value="DevDocs available"/>
1415
<stories value="MFTF DevDocs available"/>
1516
<title value="Magento Functional Testing Framework Documentation is available."/>
@@ -18,7 +19,10 @@
1819
<group value="mftf"/>
1920
</annotations>
2021

22+
<!-- Open MFTF DevDocs Page -->
2123
<amOnPage stepKey="openMFTFDevDocPage" url="{{MFTFDocPage.url}}" />
24+
<!--< > & $abc " abc ' <click stepKey="click" userInput="$$createDataHook.firstname$$" selector="#id">/-->
25+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="asdf" />
2226
<see stepKey="verifyPageIntroText" selector="{{contentSection.pageIntro}}" userInput="Introduction to the Magento Functional Testing Framework" />
2327
</test>
2428
</tests>

dev/tests/verification/Resources/AssertTest.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ class AssertTestCest
5454
);
5555

5656
$grabTextFrom1 = $I->grabTextFrom(".copyright>span"); // stepKey: grabTextFrom1
57+
$I->comment("custom asserts");
5758
$I->assertArrayIsSorted(["1", "2", "3", "4", "5"], "asc"); // stepKey: assertSorted1
5859
$I->comment("asserts without variable replacement");
60+
$I->comment("asserts without variable replacement");
5961
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayHasKey
6062
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayNotHasKey
6163
$I->assertArraySubset([1, 2], [1, 2, 3, 5], "pass"); // stepKey: assertArraySubset
@@ -91,6 +93,7 @@ class AssertTestCest
9193
$I->assertStringStartsWith("a", "apple", "pass"); // stepKey: assertStringStartsWith
9294
$I->assertTrue(true, "pass"); // stepKey: assertTrue
9395
$I->comment("asserts backward compatible");
96+
$I->comment("asserts backward compatible");
9497
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayHasKeyBackwardCompatible
9598
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayNotHasKeyBackwardCompatible
9699
$I->assertArraySubset([1, 2], [1, 2, 3, 5], "pass"); // stepKey: assertArraySubsetBackwardCompatible
@@ -133,14 +136,17 @@ class AssertTestCest
133136
$I->assertNull($text, "pass"); // stepKey: assertNullBackwardCompatible
134137
$I->expectException(new MyException('exception msg'), function() {$this->doSomethingBad();}); // stepKey: expectExceptionBackwardCompatible
135138
$I->comment("string type that use created data");
139+
$I->comment("string type that use created data");
136140
$I->assertStringStartsWith("D", PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test') . ", " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test'), "fail"); // stepKey: assert1
137141
$I->assertStringStartsNotWith("W", PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test') . ", " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'), "pass"); // stepKey: assert2
138142
$I->assertEquals(PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), "pass"); // stepKey: assert5
139143
$I->comment("array type that use created data");
144+
$I->comment("array type that use created data");
140145
$I->assertArraySubset([PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test')], [PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test'), "1"], "pass"); // stepKey: assert9
141146
$I->assertArraySubset([PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test')], [PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'), "1"], "pass"); // stepKey: assert10
142147
$I->assertArrayHasKey("lastname", ['lastname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), 'firstname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test')], "pass"); // stepKey: assert3
143148
$I->assertArrayHasKey("lastname", ['lastname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'), 'firstname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test')], "pass"); // stepKey: assert4
149+
$I->comment("this section can only be generated and cannot run");
144150
$I->assertInstanceOf(User::class, $text, "pass"); // stepKey: assertInstanceOf
145151
$I->assertNotInstanceOf(User::class, 21, "pass"); // stepKey: assertNotInstanceOf
146152
$I->assertFileExists($text, "pass"); // stepKey: assertFileExists2
@@ -151,6 +157,7 @@ class AssertTestCest
151157
$I->fail("fail"); // stepKey: fail
152158
$I->fail(PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test') . " " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test')); // stepKey: assert7
153159
$I->fail(PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test') . " " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test')); // stepKey: assert8
160+
$I->comment("assertElementContainsAttribute examples");
154161
$I->assertElementContainsAttribute("#username", "class", "admin__control-text"); // stepKey: assertElementContainsAttribute1
155162
$I->assertElementContainsAttribute("#username", "name", "login[username]"); // stepKey: assertElementContainsAttribute2
156163
$I->assertElementContainsAttribute("#username", "autofocus", "true"); // stepKey: assertElementContainsAttribute3
@@ -159,6 +166,7 @@ class AssertTestCest
159166
$I->assertElementContainsAttribute(".admin__menu-overlay", "border", "0"); // stepKey: assertElementContainsAttribute6
160167
$I->assertElementContainsAttribute("#username", "value", PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test')); // stepKey: assertElementContainsAttribute7
161168
$I->assertElementContainsAttribute("#username", "value", PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test')); // stepKey: assertElementContainsAttribute8
169+
$I->comment("assert entity resolution");
162170
$I->assertEquals("John", "Doe", "pass"); // stepKey: assertEqualsEntity
163171
}
164172
}

src/Magento/FunctionalTestingFramework/Test/Config/Converter/Dom/Flat.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public function convertXml(\DOMNode $source, $basePath = '')
124124
) {
125125
$value = $node->nodeValue;
126126
break;
127+
} elseif ($node->nodeType == XML_COMMENT_NODE) {
128+
$uniqid = uniqid(str_replace("#", "", $node->nodeName));
129+
$value[$uniqid] = [
130+
'value' => trim($node->nodeValue),
131+
'nodeName' => $node->nodeName,
132+
];
127133
}
128134
}
129135
$result = $this->getNodeAttributes($source);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
class ActionObject
2525
{
26+
const COMMENT_ACTION = '#comment';
2627
const __ENV = "_ENV";
2728
const __CREDS = "_CREDS";
2829
const RUNTIME_REFERENCES = [
@@ -148,7 +149,7 @@ public function __construct(
148149
$actionOrigin = null
149150
) {
150151
$this->stepKey = $stepKey;
151-
$this->type = $type;
152+
$this->type = $type === self::COMMENT_ACTION ? self::ACTION_TYPE_COMMENT : $type;
152153
$this->actionAttributes = $actionAttributes;
153154
$this->linkedAction = $linkedAction;
154155
$this->actionOrigin = $actionOrigin;
@@ -554,7 +555,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
554555
}
555556

556557
if ($replacement === null) {
557-
if (get_class($objectHandler) != DataObjectHandler::class) {
558+
if (!($objectHandler instanceof DataObjectHandler)) {
558559
return $this->findAndReplaceReferences(DataObjectHandler::getInstance(), $outputString);
559560
} else {
560561
throw new TestReferenceException(

src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function extractActions($testActions, $testName = null)
5858
$stepKeyRefs = [];
5959

6060
foreach ($testActions as $actionName => $actionData) {
61-
$stepKey = $actionData[self::TEST_STEP_MERGE_KEY];
61+
$stepKey = strpos($actionData[self::NODE_NAME], ActionObject::COMMENT_ACTION) === false
62+
? $actionData[self::TEST_STEP_MERGE_KEY]
63+
: $actionName;
6264
$actionType = $actionData[self::NODE_NAME];
6365

6466
if (empty($stepKey)) {

src/Magento/FunctionalTestingFramework/Test/Util/AnnotationExtractor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1010
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
11+
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1112
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1213

1314
/**
@@ -67,6 +68,9 @@ public function extractAnnotations($testAnnotations, $filename)
6768
// parse the Test annotations
6869

6970
foreach ($annotations as $annotationKey => $annotationData) {
71+
if (strpos($annotationKey, ActionObject::ACTION_TYPE_COMMENT) !== false) {
72+
continue;
73+
}
7074
$annotationValues = [];
7175
// Only transform severity annotation
7276
if ($annotationKey == "severity") {

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
13031303
case "skipReadinessCheck":
13041304
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']);
13051305
break;
1306+
case "comment":
1307+
$input = $input === null ? strtr($value, ['$' => '\$', '{' => '\{', '}' => '\}']) : $input;
13061308
default:
13071309
$testSteps .= $this->wrapFunctionCall(
13081310
$actor,

0 commit comments

Comments
 (0)