Skip to content

Commit 9fff8f2

Browse files
authored
Merge branch 'develop' into CD-develop
2 parents fd0e889 + 6ab66f3 commit 9fff8f2

18 files changed

+101
-40
lines changed

dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ActionGroupWithDataOverrideTestCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/ActionGroupWithDataTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ActionGroupWithDataTestCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ActionGroupWithNoDefaultTestCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/ActionGroupWithPersistedData.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ActionGroupWithPersistedDataCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ActionGroupWithTopLevelPersistedDataCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class ArgumentWithSameNameAsElementCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class BasicFunctionalTestCest
4646
public function _failed(AcceptanceTester $I)
4747
{
4848
$I->saveScreenshot();
49-
$this->_after($I);
5049
}
5150

5251
/**
@@ -60,6 +59,8 @@ class BasicFunctionalTestCest
6059
*/
6160
public function BasicFunctionalTest(AcceptanceTester $I)
6261
{
62+
$I->comment("");
63+
$I->comment("");
6364
$someVarDefinition = $I->grabValueFrom();
6465
$I->acceptPopup();
6566
$I->amOnPage("/test/url");
@@ -70,6 +71,8 @@ class BasicFunctionalTestCest
7071
$I->click(".functionalTestSelector");
7172
$I->clickWithLeftButton(".functionalTestSelector");
7273
$I->clickWithRightButton(".functionalTestSelector");
74+
$I->clickWithLeftButton("#element#element .200", 200, 300);
75+
$I->clickWithRightButton("#element .4123#element", 200, 300);
7376
$I->closeTab();
7477
$I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true);
7578
$I->dontSee("someInput", ".functionalTestSelector");

dev/tests/verification/Resources/BasicMergeTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class BasicMergeTestCest
4848
public function _failed(AcceptanceTester $I)
4949
{
5050
$I->saveScreenshot();
51-
$this->_after($I);
5251
}
5352

5453
/**

dev/tests/verification/Resources/HookActionsTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class HookActionsTestCest
7373
public function _failed(AcceptanceTester $I)
7474
{
7575
$I->saveScreenshot();
76-
$this->_after($I);
7776
}
7877

7978
/**

dev/tests/verification/Resources/MergedActionGroupTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class MergedActionGroupTestCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/Resources/MergedReferencesTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class MergedReferencesTestCest
4646
public function _failed(AcceptanceTester $I)
4747
{
4848
$I->saveScreenshot();
49-
$this->_after($I);
5049
}
5150

5251
/**

dev/tests/verification/Resources/MultipleActionGroupsTest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class MultipleActionGroupsTestCest
5757
public function _failed(AcceptanceTester $I)
5858
{
5959
$I->saveScreenshot();
60-
$this->_after($I);
6160
}
6261

6362
/**

dev/tests/verification/TestModule/Data/ReplacementData.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@
2626
<data key="sampleField2">moreData</data>
2727
<requiredEntity type="test2">originalValue2</requiredEntity>
2828
</entity>
29+
<entity name="offset" type="simpleData">
30+
<data key="x">200</data>
31+
<data key="y">300</data>
32+
</entity>
33+
<entity name="emptyData" type="backend">
34+
<data key="noData"></data>
35+
<data key="definitelyNoData"/>
36+
</entity>
2937
</entities>

dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<after>
2323
<amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/>
2424
</after>
25+
<comment stepKey="basicCommentWithNoData" userInput="{{emptyData.noData}}"/>
26+
<comment stepKey="basicCommentWithDefinitelyNoData" userInput="{{emptyData.definitelyNoData}}"/>
2527
<grabValueFrom stepKey="someVarDefinition"/>
2628
<acceptPopup stepKey="acceptPopupKey1"/>
2729
<amOnPage stepKey="amOnPageKey1" url="/test/url"/>
@@ -32,6 +34,8 @@
3234
<click selector=".functionalTestSelector" stepKey="clickKey1"/>
3335
<clickWithLeftButton selector=".functionalTestSelector" stepKey="clickWithLeftButtonKey1"/>
3436
<clickWithRightButton selector=".functionalTestSelector" stepKey="clickWithRightButtonKey1"/>
37+
<clickWithLeftButton selector="{{SampleSection.simpleElement}}{{SampleSection.simpleElementOneParam(offset.x)}}" x="{{offset.x}}" y="{{offset.y}}" stepKey="clickWithLeftButtonKeyXY1" />
38+
<clickWithRightButton selector="{{SampleSection.simpleElementOneParam('4123')}}{{SampleSection.simpleElement}}" x="{{offset.x}}" y="{{offset.y}}" stepKey="clickWithRightButtonKeyXY1" />
3539
<closeTab stepKey="closeTabKey1"/>
3640
<conditionalClick selector=".functionalTestSelector" dependentSelector=".functionalDependentTestSelector" visible="true" stepKey="conditionalClickKey1"/>
3741
<dontSee userInput="someInput" selector=".functionalTestSelector" stepKey="dontSeeKey1" />

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private function resolveUrlReference($urlIn, $entityObjects)
206206
EntityDataObject::CEST_UNIQUE_VALUE
207207
);
208208
if (null !== $param) {
209-
$urlOut = str_replace($paramValue, $param, $urlIn);
209+
$urlOut = str_replace($paramValue, $param, $urlOut);
210210
continue;
211211
}
212212
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Extension;
8+
9+
use \Codeception\Events;
10+
11+
/**
12+
* Class TestContextExtension
13+
* @SuppressWarnings(PHPMD.UnusedPrivateField)
14+
*/
15+
class TestContextExtension extends \Codeception\Extension
16+
{
17+
const TEST_PHASE_AFTER = "_after";
18+
19+
/**
20+
* Codeception Events Mapping to methods
21+
* @var array
22+
*/
23+
public static $events = [
24+
Events::TEST_FAIL => 'testFail',
25+
];
26+
27+
/**
28+
* Codeception event listener function, triggered on test failure.
29+
* @param \Codeception\Event\FailEvent $e
30+
* @return void
31+
*/
32+
public function testFail(\Codeception\Event\FailEvent $e)
33+
{
34+
$cest = $e->getTest();
35+
$context = $this->extractContext($e->getFail()->getTrace(), $cest->getTestMethod());
36+
// Do not attempt to run _after if failure was in the _after block
37+
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
38+
if ($context != TestContextExtension::TEST_PHASE_AFTER) {
39+
try {
40+
$actorClass = $e->getTest()->getMetadata()->getCurrent('actor');
41+
$I = new $actorClass($cest->getScenario());
42+
call_user_func(\Closure::bind(
43+
function () use ($cest, $I) {
44+
$cest->executeHook($I, 'after');
45+
},
46+
null,
47+
$cest
48+
));
49+
} catch (\Exception $e) {
50+
// Do not rethrow Exception
51+
}
52+
}
53+
}
54+
55+
/**
56+
* Extracts hook method from trace, looking specifically for the cest class given.
57+
* @param array $trace
58+
* @param string $class
59+
* @return string
60+
*/
61+
public function extractContext($trace, $class)
62+
{
63+
foreach ($trace as $entry) {
64+
$traceClass = $entry["class"] ?? null;
65+
if (strpos($traceClass, $class) != 0) {
66+
return $entry["function"];
67+
}
68+
}
69+
return null;
70+
}
71+
}

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class ActionObject
2121
{
2222
const __ENV = "_ENV";
23-
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual"];
23+
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y"];
2424
const SELECTOR_ENABLED_ATTRIBUTES = [
2525
'selector',
2626
'dependentSelector',
@@ -40,8 +40,7 @@ class ActionObject
4040
const ACTION_ATTRIBUTE_URL = 'url';
4141
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
4242
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
43-
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w]+\.[\w\[\]]+}}/';
44-
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN_WITH_PARAMS= '/{{[\w]+\.[\w]+\(.+\)}}/';
43+
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\(.+\)}})/';
4544

4645
/**
4746
* The unique identifier for the action
@@ -371,7 +370,7 @@ private function resolveDataInputReferences()
371370
foreach ($relevantDataAttributes as $dataAttribute) {
372371
$varInput = $this->actionAttributes[$dataAttribute];
373372
$replacement = $this->findAndReplaceReferences(DataObjectHandler::getInstance(), $varInput);
374-
if ($replacement != null) {
373+
if ($replacement !== null) {
375374
$this->resolvedCustomAttributes[$dataAttribute] = $replacement;
376375
}
377376
}
@@ -444,7 +443,7 @@ private function stripAndReturnParameters($reference)
444443
private function findAndReplaceReferences($objectHandler, $inputString)
445444
{
446445
//look for parameter area, if so use different regex
447-
$regex = $this->resolveRegexPatternForReference($inputString);
446+
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
448447

449448
preg_match_all($regex, $inputString, $matches);
450449

@@ -482,7 +481,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
482481
$replacement = $this->resolveEntityDataObjectReference($obj, $match);
483482
}
484483

485-
if ($replacement == null) {
484+
if ($replacement === null) {
486485
if (get_class($objectHandler) != DataObjectHandler::class) {
487486
return $this->findAndReplaceReferences(DataObjectHandler::getInstance(), $outputString);
488487
} else {
@@ -514,20 +513,6 @@ private function validateUrlAreaAgainstActionType($obj)
514513
}
515514
}
516515

517-
/**
518-
* Determines whether the given $inputString has (params), and returns the appropriate regex for use in matching.
519-
* @param string $inputString
520-
* @return string
521-
*/
522-
private function resolveRegexPatternForReference($inputString)
523-
{
524-
if (preg_match(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN_WITH_PARAMS, $inputString) === 1) {
525-
return ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN_WITH_PARAMS;
526-
} else {
527-
return ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
528-
}
529-
}
530-
531516
/**
532517
* Gets the object's dataByName with given $match, differentiating behavior between <array> and <data> nodes.
533518
* @param string $obj

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
871871
break;
872872
case "switchToNextTab":
873873
case "switchToPreviousTab":
874-
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $this->stripWrappedQuotes($input));
874+
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $input);
875875
break;
876876
case "clickWithLeftButton":
877877
case "clickWithRightButton":
@@ -1405,6 +1405,7 @@ private function stripAndSplitReference($reference, $delimiter)
14051405
* @return string
14061406
* @throws TestReferenceException
14071407
* @throws \Exception
1408+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
14081409
*/
14091410
private function generateHooksPhp($hookObjects)
14101411
{
@@ -1446,12 +1447,6 @@ private function generateHooksPhp($hookObjects)
14461447
throw new TestReferenceException($e->getMessage() . " in Element \"" . $type . "\"");
14471448
}
14481449

1449-
if ($hookObject->getType() == TestObjectExtractor::TEST_FAILED_HOOK) {
1450-
$steps.="\t\t";
1451-
$steps.='$this->_after($I);';
1452-
$steps.="\n";
1453-
}
1454-
14551450
$hooks .= sprintf("\tpublic function _{$type}(%s)\n", $dependencies);
14561451
$hooks .= "\t{\n";
14571452
$hooks .= $steps;
@@ -1627,6 +1622,9 @@ private function wrapFunctionCall($actor, $action, ...$args)
16271622
if (!$isFirst) {
16281623
$output .= ', ';
16291624
}
1625+
if ($args[$i] === "") {
1626+
$args[$i] = '"' . $args[$i] . '"';
1627+
}
16301628
$output .= $args[$i];
16311629
$isFirst = false;
16321630
}
@@ -1658,6 +1656,9 @@ private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $actio
16581656
if (!$isFirst) {
16591657
$output .= ', ';
16601658
}
1659+
if ($args[$i] === "") {
1660+
$args[$i] = '"' . $args[$i] . '"';
1661+
}
16611662
$output .= $args[$i];
16621663
$isFirst = false;
16631664
}

0 commit comments

Comments
 (0)