Skip to content

MQE-697: Grab test actions's results cannot be used in action-groups #51

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 7 commits into from
Mar 12, 2018
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class ActionGroupObjectTest extends TestCase
{
const ACTION_GROUP_MERGE_KEY = 'testKey';
const ACTION_GROUP_MERGE_KEY = 'TestKey';

/**
* Tests a string literal in an action group
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace Magento\AcceptanceTest\_generated\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 ActionGroupWithStepKeyReferencesCest
{
/**
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function ActionGroupWithStepKeyReferences(AcceptanceTester $I)
{
$I->amGoingTo("create entity that has the stepKey: createSimpleDataActionGroup");
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
$createSimpleDataActionGroup = new DataPersistenceHandler($simpleData, []);
$createSimpleDataActionGroup->createEntity();
$grabTextDataActionGroup = $I->grabTextFrom(".class");
$I->fillField(".{$grabTextDataActionGroup}", $createSimpleDataActionGroup->getCreatedDataByName('field'));
}
}
2 changes: 1 addition & 1 deletion dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BasicFunctionalTestCest
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector");
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector");
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector");
$magentoCli1 = $I->executeMagentoCLICommand("maintenance:enable");
$magentoCli1 = $I->magentoCLI("maintenance:enable");
$I->comment($magentoCli1);
$I->makeScreenshot("screenShotInput");
$I->maximizeWindow();
Expand Down
24 changes: 12 additions & 12 deletions dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ class PersistenceCustomFieldsTestCest
$UniquePerson = DataObjectHandler::getInstance()->getObject("UniquePerson");
$createdData3 = new DataPersistenceHandler($UniquePerson, [$createdData], $createdData3Fields);
$createdData3->createEntity();
$createDataAG1createdAGFields['firstname'] = "string1";
$I->amGoingTo("create entity that has the stepKey: createDataAG1createdAG");
$createDataAG1CreatedAGFields['firstname'] = "string1";
$I->amGoingTo("create entity that has the stepKey: createDataAG1CreatedAG");
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
$createDataAG1createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG1createdAGFields);
$createDataAG1createdAG->createEntity();
$createDataAG2createdAGFields['firstname'] = "Jane";
$I->amGoingTo("create entity that has the stepKey: createDataAG2createdAG");
$createDataAG1CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG1CreatedAGFields);
$createDataAG1CreatedAG->createEntity();
$createDataAG2CreatedAGFields['firstname'] = "Jane";
$I->amGoingTo("create entity that has the stepKey: createDataAG2CreatedAG");
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
$createDataAG2createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG2createdAGFields);
$createDataAG2createdAG->createEntity();
$createDataAG3createdAGFields['firstname'] = $createdData3->getCreatedDataByName('firstname');
$I->amGoingTo("create entity that has the stepKey: createDataAG3createdAG");
$createDataAG2CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG2CreatedAGFields);
$createDataAG2CreatedAG->createEntity();
$createDataAG3CreatedAGFields['firstname'] = $createdData3->getCreatedDataByName('firstname');
$I->amGoingTo("create entity that has the stepKey: createDataAG3CreatedAG");
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
$createDataAG3createdAG = new DataPersistenceHandler($simpleData, [], $createDataAG3createdAGFields);
$createDataAG3createdAG->createEntity();
$createDataAG3CreatedAG = new DataPersistenceHandler($simpleData, [], $createDataAG3CreatedAGFields);
$createDataAG3CreatedAG->createEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@
<seeElement stepKey="see1" selector="{{SampleSection.simpleElement}}"/>
<seeElement stepKey="see2" selector="{{SampleSection.simpleElementOneParam(simple.firstname)}}"/>
</actionGroup>
<actionGroup name="FunctionActionGroupWithStepKeyReferences">
<createData entity="simpleData" stepKey="createSimpleData"/>
<grabTextFrom selector=".class" stepKey="grabTextData"/>
<fillField stepKey="fill1" selector=".{$grabTextData}" userInput="$createSimpleData.field$"/>
</actionGroup>
</actionGroups>
4 changes: 4 additions & 0 deletions dev/tests/verification/TestModule/Test/ActionGroupTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,8 @@
</annotations>
<actionGroup ref="actionGroupWithStringUsage" stepKey="actionGroup"/>
</test>

<test name="ActionGroupWithStepKeyReferences">
<actionGroup ref="FunctionActionGroupWithStepKeyReferences" stepKey="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 @@ -96,4 +96,15 @@ public function testActionGroupWithSimpleDataUsageFromDefaultArgument()
{
$this->generateAndCompareTest('ActionGroupWithSimpleDataUsageFromDefaultArgument');
}

/**
* Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData)
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testActionGroupWithStepKeyReferences()
{
$this->generateAndCompareTest('ActionGroupWithStepKeyReferences');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
class ActionGroupObject
{
const ACTION_GROUP_ORIGIN_NAME = "actionGroupName";
const ACTION_GROUP_ORIGIN_TEST_REF = "testInvocationRef";

/**
* Array of variable-enabled attributes.
* @var array
Expand Down Expand Up @@ -153,12 +156,14 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)

// 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() . $actionReferenceKey] = new ActionObject(
$action->getStepKey() . $actionReferenceKey,
$resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject(
$action->getStepKey() . ucfirst($actionReferenceKey),
$action->getType(),
array_merge($action->getCustomActionAttributes(), $newActionAttributes),
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . $actionReferenceKey,
$action->getOrderOffset()
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
$action->getOrderOffset(),
[self::ACTION_GROUP_ORIGIN_NAME => $this->name,
self::ACTION_GROUP_ORIGIN_TEST_REF => $actionReferenceKey]
);
}

Expand Down Expand Up @@ -307,6 +312,19 @@ private function replacePersistedArgument($replacement, $attributeValue, $fullVa
return $newAttributeValue;
}

/**
* Finds and returns all original stepkeys of actions in actionGroup.
* @return string[]
*/
public function extractStepKeys()
{
$originalKeys = [];
foreach ($this->parsedActions as $action) {
$originalKeys[] = $action->getStepKey();
}
return $originalKeys;
}

/**
* Searches through ActionGroupObject's arguments and returns first argument wi
* @param string $name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class ActionObject
*/
private $timeout;

/**
* An array with items containing information of the origin of this action.
*
* @var array
*/
private $actionOrigin = [];

/**
* ActionObject constructor.
*
Expand All @@ -92,18 +99,21 @@ class ActionObject
* @param array $actionAttributes
* @param string|null $linkedAction
* @param string $order
* @param array $actionOrigin
*/
public function __construct(
$stepKey,
$type,
$actionAttributes,
$linkedAction = null,
$order = ActionObject::MERGE_ACTION_ORDER_BEFORE
$order = ActionObject::MERGE_ACTION_ORDER_BEFORE,
$actionOrigin = null
) {
$this->stepKey = $stepKey;
$this->type = $type;
$this->actionAttributes = $actionAttributes;
$this->linkedAction = $linkedAction;
$this->actionOrigin = $actionOrigin;

if ($order == ActionObject::MERGE_ACTION_ORDER_AFTER) {
$this->orderOffset = 1;
Expand All @@ -130,6 +140,16 @@ public function getType()
return $this->type;
}

/**
* Getter for actionOrigin
*
* @return string
*/
public function getActionOrigin()
{
return $this->actionOrigin;
}

/**
* This function returns an array of action attributes mapped by key. For example
* the tag <seeNumberOfElements selector="value1" expected="value2" stepKey=""/> has 3 attributes,
Expand Down
Loading