Skip to content

MQE-1234: Allow XML Parser to read XML comment into comment action #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dev/tests/verification/Resources/AssertTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class AssertTestCest
null
);
$grabTextFrom1 = $I->grabTextFrom(".copyright>span");
$I->comment(" custom asserts ");
$I->assertArrayIsSorted(["1", "2", "3", "4", "5"], "asc");
$I->comment(" asserts without variable replacement ");
$I->comment("asserts without variable replacement");
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass");
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass");
Expand Down Expand Up @@ -88,6 +90,7 @@ class AssertTestCest
$I->assertStringStartsNotWith("a", "banana", "pass");
$I->assertStringStartsWith("a", "apple", "pass");
$I->assertTrue(true, "pass");
$I->comment(" asserts backward compatible ");
$I->comment("asserts backward compatible");
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass");
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass");
Expand Down Expand Up @@ -130,15 +133,18 @@ class AssertTestCest
$I->assertIsEmpty($text, "pass");
$I->assertNull($text, "pass");
$I->expectException(new MyException('exception msg'), function() {$this->doSomethingBad();});
$I->comment(" string type that use created data ");
$I->comment("string type that use created data");
$I->assertStringStartsWith("D", PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test') . ", " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test'), "fail");
$I->assertStringStartsNotWith("W", PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test') . ", " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'), "pass");
$I->assertEquals(PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), "pass");
$I->comment(" array type that use created data ");
$I->comment("array type that use created data");
$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");
$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");
$I->assertArrayHasKey("lastname", ['lastname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'), 'firstname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test')], "pass");
$I->assertArrayHasKey("lastname", ['lastname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'), 'firstname' => PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test')], "pass");
$I->comment(" this section can only be generated and cannot run ");
$I->assertInstanceOf(User::class, $text, "pass");
$I->assertNotInstanceOf(User::class, 21, "pass");
$I->assertFileExists($text, "pass");
Expand All @@ -149,6 +155,7 @@ class AssertTestCest
$I->fail("fail");
$I->fail(PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test') . " " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'lastname', 'test'));
$I->fail(PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test') . " " . PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'lastname', 'test'));
$I->comment(" assertElementContainsAttribute examples ");
$I->assertElementContainsAttribute("#username", "class", "admin__control-text");
$I->assertElementContainsAttribute("#username", "name", "login[username]");
$I->assertElementContainsAttribute("#username", "autofocus", "true");
Expand All @@ -157,6 +164,7 @@ class AssertTestCest
$I->assertElementContainsAttribute(".admin__menu-overlay", "border", "0");
$I->assertElementContainsAttribute("#username", "value", PersistedObjectHandler::getInstance()->retrieveEntityField('createData2', 'firstname', 'test'));
$I->assertElementContainsAttribute("#username", "value", PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'test'));
$I->comment(" assert entity resolution ");
$I->assertEquals("John", "Doe", "pass");
}
}
83 changes: 83 additions & 0 deletions dev/tests/verification/Resources/CommentTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
* @Title("[NO TESTCASEID]: CommentTest")
* @group functional
*/
class CommentTestCest
{
/**
* @param AcceptanceTester $I
* @throws \Exception
*/
public function _before(AcceptanceTester $I)
{
$I->comment("< > & \$abc \" abc ' <click stepKey=\"click\" userInput=\"{{UniquePerson.firstname}}\" selector=\"#id\">/");
$I->amGoingTo("create entity that has the stepKey: createDataHook");
PersistedObjectHandler::getInstance()->createEntity(
"createDataHook",
"hook",
"ReplacementPerson",
[],
null
);
$I->comment("<abc>");
}

/**
* @Severity(level = SeverityLevel::CRITICAL)
* @Features({"TestModule"})
* @Stories({"MQE-1234"})
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function CommentTest(AcceptanceTester $I)
{
$I->amGoingTo("create entity that has the stepKey: createDataTest");
PersistedObjectHandler::getInstance()->createEntity(
"createDataTest",
"test",
"DefaultPerson",
[],
null
);
$I->comment("<abc");
$I->comment("abc&");
$I->comment(">abc");
$I->comment("Entering Action Group commentActionGroup (commentInTest4)");
$I->comment("xml comment in Action Group before");
$I->comment("commentInActionGroup1");
$I->wait(1);
$I->comment("commentInActionGroup2");
$I->comment("xml comment in Action Group inside");
$I->wait(1);
$I->comment("xml comment in Action Group after");
$I->comment("Exiting Action Group commentActionGroup (commentInTest4)");
$I->comment("< > & \$abc \" abc ' <click stepKey=\"click\" userInput=\"\$\$createDataHook.firstname\$\$\" selector=\"#id\">/");
$I->comment(PersistedObjectHandler::getInstance()->retrieveEntityField('createDataHook', 'firstname', 'test'));
$I->comment(PersistedObjectHandler::getInstance()->retrieveEntityField('createDataTest', 'firstname', 'test'));
$I->comment("John" . msq("UniquePerson"));
$I->comment("< > & \$abc \" abc ' <click stepKey=\"click\" userInput=\"\$createDataTest.firstname\$\" selector=\"#id\">/");
$I->comment("");
$I->comment("");
$I->skipReadinessCheck(true);
$I->comment("skipReadiness");
$I->skipReadinessCheck(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
<actionGroup name="commentActionGroup">
<!--xml comment in Action Group before-->
<comment userInput="commentInActionGroup1" stepKey="commentInActionGroup1" />
<wait time="1" stepKey="waitInActionGroup1"/>
<comment userInput="commentInActionGroup2" stepKey="commentInActionGroup2" />
<!--xml comment in Action Group inside-->
<wait time="1" stepKey="waitInActionGroup2"/>
<!--xml comment in Action Group after-->
</actionGroup>
</actionGroups>
38 changes: 38 additions & 0 deletions dev/tests/verification/TestModule/Test/CommentTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="CommentTest">
<annotations>
<severity value="CRITICAL"/>
<title value="CommentTest"/>
<group value="functional"/>
<features value="CommentTest"/>
<stories value="MQE-1234"/>
</annotations>
<before>
<!--< > & $abc " abc ' <click stepKey="click" userInput="{{UniquePerson.firstname}}" selector="#id">/-->
<createData entity="ReplacementPerson" stepKey="createDataHook"/>
<comment userInput="&lt;abc&gt;" stepKey="commentInHook"/>
</before>
<createData entity="DefaultPerson" stepKey="createDataTest"/>
<comment userInput="&lt;abc" stepKey="commentInTest1"/>
<comment userInput="abc&amp;" stepKey="commentInTest2"/>
<comment userInput="&gt;abc" stepKey="commentInTest3"/>
<actionGroup ref="commentActionGroup" stepKey="commentInTest4"/>
<!--< > & $abc " abc ' <click stepKey="click" userInput="$$createDataHook.firstname$$" selector="#id">/-->
<comment userInput="$$createDataHook.firstname$$" stepKey="commentInTest5"/>
<comment userInput="$createDataTest.firstname$" stepKey="commentInTest6"/>
<comment userInput="{{UniquePerson.firstname}}" stepKey="commentInTest8"/>
<!--< > & $abc " abc ' <click stepKey="click" userInput="$createDataTest.firstname$" selector="#id">/-->
<comment stepKey="commentInTest9" userInput="{{emptyData.noData}}"/>
<comment stepKey="commentInTest10" userInput="{{emptyData.definitelyNoData}}"/>
<comment stepKey="commentInTest11" userInput="skipReadiness" skipReadiness="true"/>
</test>
</tests>
22 changes: 22 additions & 0 deletions dev/tests/verification/Tests/CommentGenerationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace tests\verification\Tests;

use tests\util\MftfTestCase;

class CommentGenerationTest extends MftfTestCase
{
/**
* Tests flat generation of a hardcoded test file with no external references.
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testCommentGeneration()
{
$this->generateAndCompareTest('CommentTest');
}
}
6 changes: 6 additions & 0 deletions docs/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Attribute|Type|Use

See [Action groups][action group] for more information.

### XML Comments

xml comments in `/tests/test`, but other than in `/tests/test/annotations`, will be parse and converted in place into `comment` actions.

xml comments in `/actionGroups/actionGroup`, but other than in `/actionGroups/actionGroup/arguments`, will be parse and converted in place into `comment` action.

<!-- Link definitions -->

[`<actionGroup>`]: #actiongroup-tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Flat implements ConverterInterface
const REMOVE_KEY_ATTRIBUTE = 'keyForRemoval';
const EXTENDS_ATTRIBUTE = 'extends';
const TEST_HOOKS = ['before', 'after'];
const COMMENT_ACTION = 'comment';
const XML_COMMENT_ACTION = 'xmlComment';

/**
* Array node configuration.
Expand Down Expand Up @@ -119,6 +121,23 @@ public function convertXml(\DOMNode $source, $basePath = '')
} else {
$value[$nodeName] = $nodeData;
}
// A new "xmlComment" node is inserted when xml comment is found in non-annotation portion of tests
// or in non-arguments portion of action groups
} elseif ($node->nodeType == XML_COMMENT_NODE) {
if ((strpos($basePath, '/tests/test') !== false
&& strpos($basePath, '/tests/test/annotations') === false)
|| (strpos($basePath, '/actionGroups/actionGroup') !== false
&& strpos($basePath, '/actionGroups/actionGroup/arguments') === false)) {
$nodePath = $basePath . '/' . self::COMMENT_ACTION;
$arrayKeyAttribute = $this->arrayNodeConfig->getAssocArrayKeyAttribute($nodePath);
$arrayKeyValue = self::COMMENT_ACTION . uniqid();
$nodeData = [
"nodeName" => self::XML_COMMENT_ACTION,
"userInput" => $node->nodeValue,
$arrayKeyAttribute => $arrayKeyValue,
];
$value[$arrayKeyValue] = $nodeData;
}
} elseif ($node->nodeType == XML_CDATA_SECTION_NODE
|| ($node->nodeType == XML_TEXT_NODE && trim($node->nodeValue) != '')
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ActionObject
const DEFAULT_WAIT_TIMEOUT = 10;
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
const ACTION_TYPE_COMMENT = 'comment';
const ACTION_TYPE_XML_COMMENT = 'xmlComment';

/**
* The unique identifier for the action
Expand Down Expand Up @@ -191,7 +192,7 @@ public function getType()
/**
* Getter for actionOrigin
*
* @return string
* @return array
*/
public function getActionOrigin()
{
Expand Down Expand Up @@ -267,7 +268,7 @@ public function setTimeout($timeout)
*/
public function resolveReferences()
{
if (empty($this->resolvedCustomAttributes)) {
if (empty($this->resolvedCustomAttributes) && $this->getType() != self::ACTION_TYPE_XML_COMMENT) {
$this->trimAssertionAttributes();
$this->resolveSelectorReferenceAndTimeout();
$this->resolveUrlReference();
Expand Down
Loading