Skip to content

MQE-913: Nested Element Assertions Don’t Support Action Group Replacement #90

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 5 commits into from
Apr 10, 2018
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,33 @@
<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
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 ActionGroupUsingNestedArgumentCest
{
/**
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function ActionGroupUsingNestedArgument(AcceptanceTester $I)
{
$grabProductsActionGroup = $I->grabMultiple("selector");
$I->assertCount(99, $grabProductsActionGroup);
}
}
11 changes: 11 additions & 0 deletions dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@
</arguments>
<see selector="{{SampleSection.oneParamElement(someArgument)}}" userInput="{{someArgument}}" stepKey="see1" />
</actionGroup>

<actionGroup name="actionGroupWithNestedArgument">
<arguments>
<argument name="count" defaultValue="10" type="string"/>
</arguments>
<grabMultiple selector="selector" stepKey="grabProducts"/>
<assertCount stepKey="assertCount">
<expectedResult type="int">{{count}}</expectedResult>
<actualResult type="variable">grabProducts</actualResult>
</assertCount>
</actionGroup>
</actionGroups>
6 changes: 6 additions & 0 deletions dev/tests/verification/TestModule/Test/ActionGroupTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,10 @@
<test name="ActionGroupWithStepKeyReferences">
<actionGroup ref="FunctionActionGroupWithStepKeyReferences" stepKey="actionGroup"/>
</test>

<test name="ActionGroupUsingNestedArgument">
<actionGroup ref="actionGroupWithNestedArgument" stepKey="actionGroup">
<argument name="count" value="99"/>
</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 @@ -107,4 +107,15 @@ public function testActionGroupWithStepKeyReferences()
{
$this->generateAndCompareTest('ActionGroupWithStepKeyReferences');
}

/**
* Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData)
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testActionGroupWithNestedArgument()
{
$this->generateAndCompareTest('ActionGroupUsingNestedArgument');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,23 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
{
$resolvedActions = [];

// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
// $matches[1] = section.element
// $matches[2] = arg.field
$regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/';

foreach ($this->parsedActions as $action) {
$varAttributes = array_intersect($this->varAttributes, array_keys($action->getCustomActionAttributes()));
$newActionAttributes = [];

if (!empty($varAttributes)) {
// 1 check to see if we have pertinent var
foreach ($varAttributes as $varAttribute) {
$attributeValue = $action->getCustomActionAttributes()[$varAttribute];
preg_match_all($regexPattern, $attributeValue, $matches);
if (empty($matches[0])) {
continue;
}

//get rid of full match {{arg.field(arg.field)}}
array_shift($matches);

$newActionAttributes[$varAttribute] = $this->replaceAttributeArguments(
$arguments,
$attributeValue,
$matches
);
}
$newActionAttributes = $this->resolveAttributesWithArguments(
$arguments,
$action->getCustomActionAttributes()
);
}

// we append the action reference key to any linked action and the action's merge key as the user might
// use this action group multiple times in the same test.
$resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject(
$action->getStepKey() . ucfirst($actionReferenceKey),
$action->getType(),
array_merge($action->getCustomActionAttributes(), $newActionAttributes),
array_replace_recursive($action->getCustomActionAttributes(), $newActionAttributes),
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
$action->getOrderOffset(),
[self::ACTION_GROUP_ORIGIN_NAME => $this->name,
Expand All @@ -170,6 +152,50 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
return $resolvedActions;
}

/**
* Resolves all references to arguments in attributes, and subAttributes.
* @param array $arguments
* @param array $attributes
* @return array
*/
private function resolveAttributesWithArguments($arguments, $attributes)
{
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
// $matches[1] = section.element
// $matches[2] = arg.field
$regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/';

$newActionAttributes = [];
foreach ($attributes as $attributeKey => $attributeValue) {

if (is_array($attributeValue)) {
// attributes with child elements are parsed as an array, need make recursive call to resolve children
$newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments(
$arguments,
$attributeValue
);
continue;
}

preg_match_all($regexPattern, $attributeValue, $matches);

if (empty($matches[0])) {
continue;
}

//get rid of full match {{arg.field(arg.field)}}
array_shift($matches);

$newActionAttributes[$attributeKey] = $this->replaceAttributeArguments(
$arguments,
$attributeValue,
$matches
);
}
return $newActionAttributes;

}

/**
* Function that takes an array of replacement arguments, and matches them with args in an actionGroup's attribute.
* Determines if the replacement arguments are persisted data, and replaces them accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
class ActionObject
{
const __ENV = "_ENV";
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y"];
const DATA_ENABLED_ATTRIBUTES = [
"userInput",
"parameterArray",
"expected",
"actual",
"x",
"y",
"expectedResult",
"actualResult"
];
const SELECTOR_ENABLED_ATTRIBUTES = [
'selector',
'dependentSelector',
Expand Down