Skip to content

Commit a934c0b

Browse files
authored
Merge pull request #150 from magento-commerce/develop
MFTF 3.8.0 Release preparation
2 parents 40dd3eb + c930b9a commit a934c0b

File tree

11 files changed

+127
-24
lines changed

11 files changed

+127
-24
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Magento Functional Testing Framework Changelog
22
================================================
3+
3.8.0
4+
---------
5+
6+
### Updates:
7+
* Allow MFTF Helpers to Return Data to MFTF Test
8+
* Improve parallel grouping and fix an issue with unbalanced groups
9+
* Added new action WaitForElementClickable
10+
311
3.7.3
412
---------
513

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento2-functional-testing-framework",
33
"description": "Magento2 Functional Testing Framework",
44
"type": "library",
5-
"version": "3.7.3",
5+
"version": "3.8.0",
66
"license": "AGPL-3.0",
77
"keywords": ["magento", "automation", "functional", "testing"],
88
"config": {

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/functional/tests/MFTF/DevDocs/Helper/CustomHelper.php

+11
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@ public function goTo(
4646
print('$bla = ' . $bla . PHP_EOL);
4747
print('array $arraysomething = [' . implode(', ', $arraysomething) . ']' . PHP_EOL);
4848
}
49+
50+
/**
51+
* Returns value of provided param $text
52+
*
53+
* @param string $text
54+
* @return string
55+
*/
56+
public function getText(string $text): string
57+
{
58+
return $text;
59+
}
4960
}

dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
<argument name="int">987</argument>
4343
</helper>
4444

45+
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="getText" stepKey="getText">
46+
<argument name="text">some text</argument>
47+
</helper>
48+
<assertEquals stepKey="assertHelperReturnValue" message="Method getText of CustomHelper should return value which may be used as variable in test">
49+
<expectedResult type="string">some text</expectedResult>
50+
<actualResult type="variable">getText</actualResult>
51+
</assertEquals>
52+
4553
<actionGroup ref="HelperActionGroup" stepKey="actionGroupWithCustomHelper">
4654
<argument name="test" value="{{HelperData.entityField}}" />
4755
<argument name="entityTest" value="HelperData" />

dev/tests/verification/Resources/DataActionsTest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DataActionsTestCest
5353
*/
5454
public function DataActionsTest(AcceptanceTester $I)
5555
{
56+
$I->waitForElementClickable(".functionalTestSelector"); // stepKey: waitForElementClickable
5657
$I->createEntity("createdInTest", "test", "entity", [], []); // stepKey: createdInTest
5758
$I->updateEntity("createdInTest", "test", "entity",[]); // stepKey: updateInTest
5859
$I->deleteEntity("createdInTest", "test"); // stepKey: deleteInTest

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<createData entity="entity" stepKey="createdInBefore"/>
1414
<updateData entity="entity" createDataKey="createdInBefore" stepKey="updateInBefore"/>
1515
<deleteData createDataKey="createdInBefore" stepKey="deleteInBefore"/>
16-
</before>
1716

17+
</before>
18+
<waitForElementClickable selector=".functionalTestSelector" time="30" stepKey="waitForElementClickable" />
1819
<createData entity="entity" stepKey="createdInTest"/>
1920
<updateData entity="entity" createDataKey="createdInTest" stepKey="updateInTest"/>
2021
<deleteData createDataKey="createdInTest" stepKey="deleteInTest"/>

docs/test/actions.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -2374,10 +2374,28 @@ Attribute|Type|Use|Description
23742374
#### Example
23752375

23762376
```xml
2377-
<!-- Wait up to 30 seconds for `<div id="changedElement" ... >...</div>` to become visible on the page before continuing. -->
23782377
<waitForElementVisible selector="#changedElement" stepKey="waitForElementVisible"/>
23792378
```
23802379

2380+
### waitForElementClickable
2381+
2382+
See [waitForElementClickable docs on codeception.com](http://codeception.com/docs/modules/WebDriver#waitForElementClickable).
2383+
2384+
Attribute|Type|Use|Description
2385+
---|---|---|---
2386+
`selector`|string|optional| The selector identifying the corresponding HTML element.
2387+
`time`|string|optional| The number of seconds to wait for the element to appear.
2388+
`stepKey`|string|required| A unique identifier of the action.
2389+
`before`|string|optional| `stepKey` of action that must be executed next.
2390+
`after`|string|optional| `stepKey` of preceding action.
2391+
2392+
#### Example
2393+
2394+
```xml
2395+
<!-- Waits up to $timeout seconds for the given element to be clickable. If element doesn’t become clickable, a timeout exception is thrown. -->
2396+
<waitForElementClickable selector="#changedElement" stepKey="waitForElementClickable"/>
2397+
```
2398+
23812399
### waitForJS
23822400

23832401
See [waitForJS docs on codeception.com](http://codeception.com/docs/modules/WebDriver#waitForJS).

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

+41-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,35 @@ class TestObject
2121

2222
const TEST_ACTION_WEIGHT = [
2323
'waitForPageLoad' => 1500,
24-
'amOnPage' => 1000,
24+
'amOnPage' => 1500,
2525
'waitForLoadingMaskToDisappear' => 500,
2626
'wait' => self::WAIT_TIME_ATTRIBUTE,
27+
'waitForAjaxLoad' => 500,
28+
'waitForElementNotVisible' => 500,
29+
'waitForElementVisible' => 500,
30+
'waitForText' => 500,
31+
'waitForElement' => 500,
32+
'waitForJS' => 500,
2733
'comment' => 5,
2834
'assertCount' => 5,
29-
'closeAdminNotification' => 10
35+
'closeAdminNotification' => 10,
36+
'magentoCLI' => 1000,
37+
'magentoCron' => 3000,
38+
'createData' => 500,
39+
'deleteData' => 200,
40+
'updateData' => 200,
41+
'getOTP' => 1000,
3042
];
3143

44+
const WEBAPI_AUTH_TEST_ACTIONS = [
45+
'createData',
46+
'deleteData',
47+
'updateData',
48+
'getData',
49+
];
50+
51+
const WEBAPI_AUTH_TEST_ACTION_WEIGHT = 6000;
52+
3253
/**
3354
* Name of the test
3455
*
@@ -85,6 +106,13 @@ class TestObject
85106
*/
86107
private $deprecated;
87108

109+
/**
110+
* Indicates if a test contains an action that requires Web API authentication.
111+
*
112+
* @var boolean
113+
*/
114+
private $hasWebApiAuthAction;
115+
88116
/**
89117
* TestObject constructor.
90118
*
@@ -112,6 +140,7 @@ public function __construct(
112140
$this->filename = $filename;
113141
$this->parentTest = $parentTest;
114142
$this->deprecated = $deprecated;
143+
$this->hasWebApiAuthAction = false;
115144
}
116145

117146
/**
@@ -222,7 +251,11 @@ public function getEstimatedDuration()
222251

223252
$testTime = $this->calculateWeightedActionTimes($this->getOrderedActions());
224253

225-
return $hookTime + $testTime;
254+
if ($this->hasWebApiAuthAction) {
255+
return $hookTime + $testTime + self::WEBAPI_AUTH_TEST_ACTION_WEIGHT;
256+
} else {
257+
return $hookTime + $testTime;
258+
}
226259
}
227260

228261
/**
@@ -237,6 +270,11 @@ private function calculateWeightedActionTimes($actions)
237270
// search for any actions of special type
238271
foreach ($actions as $action) {
239272
/** @var ActionObject $action */
273+
274+
if (!$this->hasWebApiAuthAction && in_array($action->getType(), self::WEBAPI_AUTH_TEST_ACTIONS)) {
275+
$this->hasWebApiAuthAction = true;
276+
}
277+
240278
if (array_key_exists($action->getType(), self::TEST_ACTION_WEIGHT)) {
241279
$weight = self::TEST_ACTION_WEIGHT[$action->getType()];
242280
if ($weight === self::WAIT_TIME_ATTRIBUTE) {

src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd

+17
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<xs:element type="waitForPwaElementNotVisibleType" name="waitForPwaElementNotVisible" minOccurs="0" maxOccurs="unbounded"/>
2424
<xs:element type="waitForPwaElementVisibleType" name="waitForPwaElementVisible" minOccurs="0" maxOccurs="unbounded"/>
2525
<xs:element type="waitForTextType" name="waitForText" minOccurs="0" maxOccurs="unbounded"/>
26+
<xs:element type="waitForElementClickableType" name="waitForElementClickable" minOccurs="0" maxOccurs="unbounded"/>
27+
2628
</xs:choice>
2729
</xs:group>
2830

@@ -224,4 +226,19 @@
224226
</xs:extension>
225227
</xs:simpleContent>
226228
</xs:complexType>
229+
<xs:complexType name="waitForElementClickableType">
230+
<xs:annotation>
231+
<xs:documentation>
232+
Waits up to $timeout seconds for the given element to be clickable.
233+
If element doesn’t become clickable, a timeout exception is thrown.
234+
</xs:documentation>
235+
</xs:annotation>
236+
<xs:simpleContent>
237+
<xs:extension base="xs:string">
238+
<xs:attribute ref="selector" use="required"/>
239+
<xs:attribute ref="time"/>
240+
<xs:attributeGroup ref="commonActionAttributes"/>
241+
</xs:extension>
242+
</xs:simpleContent>
243+
</xs:complexType>
227244
</xs:schema>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+18-17
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
898898
$stepKey,
899899
$customActionAttributes['class'] . '::' . $customActionAttributes['method']
900900
);
901-
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $arguments);
901+
$testSteps .= $this->wrapFunctionCallWithReturnValue(
902+
$stepKey,
903+
$actor,
904+
$actionObject,
905+
$arguments
906+
);
902907
break;
903908
case "createData":
904909
$entity = $customActionAttributes['entity'];
@@ -2016,16 +2021,7 @@ private function addDollarSign($input)
20162021
*/
20172022
private function wrapFunctionCall($actor, $action, ...$args)
20182023
{
2019-
$isFirst = true;
2020-
$isActionHelper = $action->getType() === 'helper';
2021-
$actionType = $action->getType();
2022-
if ($isActionHelper) {
2023-
$actor = "this->helperContainer->get('" . $action->getCustomActionAttributes()['class'] . "')";
2024-
$args = $args[0];
2025-
$actionType = $action->getCustomActionAttributes()['method'];
2026-
}
2027-
2028-
$output = sprintf("\t\t$%s->%s(", $actor, $actionType);
2024+
$output = sprintf("\t\t$%s->%s(", $actor, $action->getType());
20292025
for ($i = 0; $i < count($args); $i++) {
20302026
if (null === $args[$i]) {
20312027
continue;
@@ -2046,17 +2042,22 @@ private function wrapFunctionCall($actor, $action, ...$args)
20462042
/**
20472043
* Wrap parameters into a function call with a return value.
20482044
*
2049-
* @param string $returnVariable
2050-
* @param string $actor
2051-
* @param string $action
2052-
* @param array ...$args
2045+
* @param string $returnVariable
2046+
* @param string $actor
2047+
* @param actionObject $action
2048+
* @param array ...$args
20532049
* @return string
20542050
* @throws \Exception
20552051
*/
20562052
private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $action, ...$args)
20572053
{
2058-
$isFirst = true;
2059-
$output = sprintf("\t\t$%s = $%s->%s(", $returnVariable, $actor, $action->getType());
2054+
$actionType = $action->getType();
2055+
if ($actionType === 'helper') {
2056+
$actor = "this->helperContainer->get('" . $action->getCustomActionAttributes()['class'] . "')";
2057+
$args = $args[0];
2058+
$actionType = $action->getCustomActionAttributes()['method'];
2059+
}
2060+
$output = sprintf("\t\t$%s = $%s->%s(", $returnVariable, $actor, $actionType);
20602061
for ($i = 0; $i < count($args); $i++) {
20612062
if (null === $args[$i]) {
20622063
continue;

0 commit comments

Comments
 (0)