Skip to content

Commit cbe8670

Browse files
committed
MQE-761: Generation of _failed method with createData action will lead test execution to fatal error
- reference _after method in _failed block - remove unused extractor - change Test Generator to skip generated stubs for failed function
1 parent a1f0632 commit cbe8670

18 files changed

+183
-128
lines changed

dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ActionGroupWithDataOverrideTestCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/ActionGroupWithDataTest.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ActionGroupWithDataTestCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ActionGroupWithNoDefaultTestCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/ActionGroupWithPersistedData.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ActionGroupWithPersistedDataCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ActionGroupWithTopLevelPersistedDataCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class ArgumentWithSameNameAsElementCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BasicFunctionalTestCest
4848
public function _failed(AcceptanceTester $I)
4949
{
5050
$I->saveScreenshot();
51-
$I->amOnPage("/afterUrl");
51+
$this->_after($I);
5252
}
5353

5454
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_generated\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use \Codeception\Util\Locator;
9+
use Yandex\Allure\Adapter\Annotation\Features;
10+
use Yandex\Allure\Adapter\Annotation\Stories;
11+
use Yandex\Allure\Adapter\Annotation\Title;
12+
use Yandex\Allure\Adapter\Annotation\Description;
13+
use Yandex\Allure\Adapter\Annotation\Parameter;
14+
use Yandex\Allure\Adapter\Annotation\Severity;
15+
use Yandex\Allure\Adapter\Model\SeverityLevel;
16+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
17+
18+
/**
19+
*/
20+
class HookActionsTestCest
21+
{
22+
/**
23+
* @var DataPersistenceHandler $sampleCreateBefore;
24+
*/
25+
protected $sampleCreateBefore;
26+
27+
/**
28+
* @var DataPersistenceHandler $sampleCreateForAfter;
29+
*/
30+
protected $sampleCreateForAfter;
31+
32+
/**
33+
* @param AcceptanceTester $I
34+
* @throws \Exception
35+
*/
36+
public function _before(AcceptanceTester $I)
37+
{
38+
$I->amGoingTo("create entity that has the stepKey: sampleCreateBefore");
39+
$sampleCreatedEntity = DataObjectHandler::getInstance()->getObject("sampleCreatedEntity");
40+
$this->sampleCreateBefore = new DataPersistenceHandler($sampleCreatedEntity);
41+
$this->sampleCreateBefore->createEntity();
42+
$I->amGoingTo("delete entity that has the createDataKey: sampleCreateBefore");
43+
$this->sampleCreateBefore->deleteEntity();
44+
$I->amGoingTo("create entity that has the stepKey: sampleCreateForAfter");
45+
$sampleCreatedEntity = DataObjectHandler::getInstance()->getObject("sampleCreatedEntity");
46+
$this->sampleCreateForAfter = new DataPersistenceHandler($sampleCreatedEntity);
47+
$this->sampleCreateForAfter->createEntity();
48+
}
49+
50+
/**
51+
* @var DataPersistenceHandler $sampleCreateAfter;
52+
*/
53+
protected $sampleCreateAfter;
54+
55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _after(AcceptanceTester $I)
60+
{
61+
$I->amGoingTo("create entity that has the stepKey: sampleCreateAfter");
62+
$sampleCreatedEntity = DataObjectHandler::getInstance()->getObject("sampleCreatedEntity");
63+
$this->sampleCreateAfter = new DataPersistenceHandler($sampleCreatedEntity);
64+
$this->sampleCreateAfter->createEntity();
65+
$I->amGoingTo("delete entity that has the createDataKey: sampleCreateForAfter");
66+
$this->sampleCreateForAfter->deleteEntity();
67+
}
68+
69+
/**
70+
* @param AcceptanceTester $I
71+
* @throws \Exception
72+
*/
73+
public function _failed(AcceptanceTester $I)
74+
{
75+
$I->saveScreenshot();
76+
$this->_after($I);
77+
}
78+
79+
/**
80+
* @Parameter(name = "AcceptanceTester", value="$I")
81+
* @param AcceptanceTester $I
82+
* @return void
83+
* @throws \Exception
84+
*/
85+
public function HookActionsTest(AcceptanceTester $I)
86+
{
87+
}
88+
}

dev/tests/verification/Resources/MergedActionGroupTest.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class MergedActionGroupTestCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**

dev/tests/verification/Resources/MultipleActionGroupsTest.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class MultipleActionGroupsTestCest
5959
public function _failed(AcceptanceTester $I)
6060
{
6161
$I->saveScreenshot();
62-
$I->fillField("#foo", "myData1");
63-
$I->fillField("#bar", "myData2");
62+
$this->_after($I);
6463
}
6564

6665
/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="HookActionsTest">
12+
<before>
13+
<createData entity="sampleCreatedEntity" stepKey="sampleCreateBefore"/>
14+
<deleteData createDataKey="sampleCreateBefore" stepKey="sampleDeleteBefore"/>
15+
<createData entity="sampleCreatedEntity" stepKey="sampleCreateForAfter"/>
16+
</before>
17+
<after>
18+
<createData entity="sampleCreatedEntity" stepKey="sampleCreateAfter"/>
19+
<deleteData createDataKey="sampleCreateForAfter" stepKey="sampleDeleteAfter"/>
20+
</after>
21+
</test>
22+
</tests>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\verification\Tests;
7+
8+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
9+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class HookActionsTest extends TestCase
13+
{
14+
const RESOURCES_PATH = __DIR__ . '/../Resources';
15+
16+
/**
17+
* Tests flat generation of a hardcoded test file with no external references.
18+
*
19+
* @throws \Exception
20+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
21+
*/
22+
public function testHookGenerationWithPersistedDeclarations()
23+
{
24+
$testName = 'HookActionsTest';
25+
$test = TestObjectHandler::getInstance()->getObject($testName);
26+
$testHandler = TestGenerator::getInstance(null, [$test]);
27+
$testHandler->createAllTestFiles();
28+
29+
$this->assertFileEquals(
30+
self::RESOURCES_PATH . DIRECTORY_SEPARATOR . $testName . ".txt",
31+
$testHandler->getExportDir() . DIRECTORY_SEPARATOR . $test->getCodeceptionName() . ".php"
32+
);
33+
}
34+
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ public function getActions()
7474
$mergeUtil = new ActionMergeUtil($this->parentName, $this->getType());
7575
$mergedSteps = $mergeUtil->resolveActionSteps($this->actions);
7676

77-
// add explicit call to save screenshot in order to preserve state of application after failure
78-
if ($this->getType() == TestObjectExtractor::TEST_FAILED_HOOK) {
79-
$saveScreenshotStep = ["saveScreenshot" => new ActionObject("saveScreenshot", "saveScreenshot", [])];
80-
$mergedSteps = $saveScreenshotStep + $mergedSteps;
81-
}
82-
8377
return $mergedSteps;
8478
}
8579

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public function extractActions($testActions)
4545

4646
foreach ($testActions as $actionName => $actionData) {
4747
$stepKey = $actionData[self::TEST_STEP_MERGE_KEY];
48-
if ($actionData[self::NODE_NAME] === TestEntityExtractor::TEST_STEP_ENTITY_CREATION) {
49-
$actionData = $this->stripDataFields($actionData);
50-
}
5148

5249
$actionAttributes = $this->stripDescriptorTags(
5350
$actionData,
@@ -112,23 +109,4 @@ private function processActionGroupArgs($actionAttributeData)
112109

113110
return $actionAttributeArgData;
114111
}
115-
116-
/**
117-
* Function which checks an entity definition for type array and strips this key out (as data is not stores in this
118-
* type of object).
119-
*
120-
* @param array $entityDataArray
121-
* @return array
122-
*/
123-
private function stripDataFields($entityDataArray)
124-
{
125-
$results = $entityDataArray;
126-
foreach ($entityDataArray as $key => $attribute) {
127-
if (is_array($attribute)) {
128-
unset($results[$key]);
129-
}
130-
}
131-
132-
return $results;
133-
}
134112
}

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\FunctionalTestingFramework\Test\Util;
88

9+
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
910
use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
1011

1112
/**
@@ -20,20 +21,12 @@ class TestHookObjectExtractor extends BaseObjectExtractor
2021
*/
2122
private $actionObjectExtractor;
2223

23-
/**
24-
* Test Entity Extractor object
25-
*
26-
* @var TestEntityExtractor
27-
*/
28-
private $testEntityExtractor;
29-
3024
/**
3125
* TestHookObjectExtractor constructor
3226
*/
3327
public function __construct()
3428
{
3529
$this->actionObjectExtractor = new ActionObjectExtractor();
36-
$this->testEntityExtractor = new TestEntityExtractor();
3730
}
3831

3932
/**
@@ -55,8 +48,21 @@ public function extractHook($parentName, $hookType, $testHook)
5548
$hook = new TestHookObject(
5649
$hookType,
5750
$parentName,
58-
$this->actionObjectExtractor->extractActions($hookActions),
59-
$this->testEntityExtractor->extractTestEntities($hookActions)
51+
$this->actionObjectExtractor->extractActions($hookActions)
52+
);
53+
54+
return $hook;
55+
}
56+
57+
public function createDefaultFailedHook($parentName)
58+
{
59+
60+
$saveScreenshotStep = ["saveScreenshot" => new ActionObject("saveScreenshot", "saveScreenshot", [])];
61+
62+
$hook = new TestHookObject(
63+
TestObjectExtractor::TEST_FAILED_HOOK,
64+
$parentName,
65+
$saveScreenshotStep
6066
);
6167

6268
return $hook;

0 commit comments

Comments
 (0)