Skip to content

MQE-1373: Cannot Use Data Returned By Test Actions As Substitutable V… #424

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

Merged
merged 3 commits into from
Aug 21, 2019
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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;

/**
*/
class ActionGroupWithParameterizedElementsWithStepKeyReferencesCest
{
/**
* @Features({"TestModule"})
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function ActionGroupWithParameterizedElementsWithStepKeyReferences(AcceptanceTester $I)
{
$I->comment("Entering Action Group [actionGroup] actionGroupWithParametrizedSelectors");
$testVariableActionGroup = $I->executeJS("return 1"); // stepKey: testVariableActionGroup
$testVariable2ActionGroup = $I->executeJS("return 'test'"); // stepKey: testVariable2ActionGroup
$I->comment("[createSimpleDataActionGroup] create 'simpleData' entity");
PersistedObjectHandler::getInstance()->createEntity(
"createSimpleDataActionGroup",
"test",
"simpleData",
[],
[]
);

$I->click("#{$testVariable2ActionGroup} .John"); // stepKey: click1ActionGroup
$I->click("#Doe-" . msq("simpleParamData") . "prename .{$testVariableActionGroup}"); // stepKey: click2ActionGroup
$I->seeElement("//div[@name='Tiberius'][@class={$testVariableActionGroup}][@data-element='{$testVariable2ActionGroup}'][" . PersistedObjectHandler::getInstance()->retrieveEntityField('createSimpleData', 'name', 'test') . "]"); // stepKey: see1ActionGroup
$I->comment("Exiting Action Group [actionGroup] actionGroupWithParametrizedSelectors");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@
</arguments>
<executeJS function="{{section.oneParamElement('full-width')}}" stepKey="keyone"/>
</actionGroup>
<actionGroup name="actionGroupWithParametrizedSelectors">
<arguments>
<argument name="param" type="entity"/>
<argument name="param2" type="entity" defaultValue="simpleParamData"/>
</arguments>
<executeJS function="return 1" stepKey="testVariable"/>
<executeJS function="return 'test'" stepKey="testVariable2"/>
<createData entity="simpleData" stepKey="createSimpleData"/>
<click selector="{{SampleSection.twoParamElement({$testVariable2}, param.firstname)}}" stepKey="click1"/>
<click selector="{{SampleSection.threeParamElement(param.lastname, param2.uniqueNamePre, {$testVariable})}}" stepKey="click2"/>
<seeElement selector="{{SampleSection.fourParamElement(param.middlename, {$testVariable}, {$testVariable2}, $$createSimpleData.name$$)}}" stepKey="see1"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<element name="oneParamElement" type="button" selector="#element .{{var1}}" parameterized="true"/>
<element name="twoParamElement" type="button" selector="#{{var1}} .{{var2}}" parameterized="true"/>
<element name="threeParamElement" type="button" selector="#{{var1}}-{{var2}} .{{var3}}" parameterized="true"/>
<element name="fourParamElement" type="input" selector="//div[@name='{{arg1}}'][@class={{arg2}}][@data-element='{{arg3}}'][{{arg4}}]" parameterized="true"/>
<element name="threeOneDuplicateParamElement" type="button" selector="#{{var1}}-{{var2}} .{{var1}} [{{var3}}]" parameterized="true"/>
<element name="timeoutElement" type="button" selector="#foo" timeout="30"/>
<element name="mergeElement" type="button" selector="#unMerge"/>
Expand Down
7 changes: 7 additions & 0 deletions dev/tests/verification/TestModule/Test/ActionGroupTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,11 @@
<argument name="section" value="SampleSection"/>
</actionGroup>
</test>

<test name="ActionGroupWithParameterizedElementsWithStepKeyReferences">
<actionGroup ref="actionGroupWithParametrizedSelectors" stepKey="actionGroup">
<argument name="param" value="simpleData"/>
<argument name="param2" value="simpleParamData"/>
</actionGroup>
</test>
</tests>
11 changes: 11 additions & 0 deletions dev/tests/verification/Tests/ActionGroupGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,15 @@ public function testActionGroupWithXmlComments()
{
$this->generateAndCompareTest('XmlCommentedActionGroupTest');
}

/**
* Test generation of a test referencing an action group with selectors referencing stepKeys.
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testActionGroupWithActionStepKeyReferencesInSelectors()
{
$this->generateAndCompareTest('ActionGroupWithParameterizedElementsWithStepKeyReferences');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private function resolveAttributesWithArguments($arguments, $attributes)
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
// $matches[1] = section.element
// $matches[2] = arg.field
$regexPattern = '/{{([^(}]+)\(*([^)}]+)*\)*}}/';
$regexPattern = '/{{([^(}]+)\(*([^)]+)*?\)*}}/';

$newActionAttributes = [];
foreach ($attributes as $attributeKey => $attributeValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,8 +1482,10 @@ private function resolveStepKeyReferences($input, $actionGroupOrigin, $matchAll
$persistedVarRefInvoked = "PersistedObjectHandler::getInstance()->retrieveEntityField('"
. $stepKey . $testInvocationKey . "', 'field', 'test')";

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

if (strpos($output, $persistedVarRef) !== false) {
Expand Down