Skip to content

Commit 59831de

Browse files
authored
Merge branch 'develop' into MQE-1534
2 parents 7a89cff + 38e5a69 commit 59831de

File tree

5 files changed

+100
-31
lines changed

5 files changed

+100
-31
lines changed

docs/commands/mftf.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ This command cleans up the previously generated tests; generates and runs the te
6868
For more details about `failed`, refer to [Reporting][].
6969

7070
### Generate documentation for action groups
71+
7172
```bash
7273
vendor/bin/mftf generate:docs
7374
```
@@ -115,14 +116,14 @@ vendor/bin/mftf generate:tests [option] [<test name>] [<test name>] [--remove]
115116

116117
#### Options
117118

118-
| Option | Description |
119-
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120-
| `--config=[<default>|<singleRun>|<parallel>]` | Creates a single manifest file with a list of all tests. The default location is `tests/functional/Magento/FunctionalTest/_generated/testManifest.txt`.<br/> You can split the list into multiple groups using `--config=parallel`; the groups will be generated in `_generated/groups/` like `_generated/groups/group1.txt, group2.txt, ...`.</br> Available values: `default` (default), `singleRun`(same as `default`), and `parallel`.</br> Example: `generate:tests --config=parallel`. |
121-
| `--force` | Forces test generation, regardless of the module merge order defined in the Magento instance. Example: `generate:tests --force`. |
122-
| `-i,--time` | Set time in minutes to determine the group size when `--config=parallel` is used. The __default value__ is `10`. Example: `generate:tests --config=parallel --time=15` |
123-
| `--tests` | Defines the test configuration as a JSON string. |
124-
| `--debug` | Returns additional debug information (such as the filename where an error occurred) when test generation fails because of an invalid XML schema. This parameter takes extra processing time. Use it after test generation has failed once. |
125-
| `-r,--remove` | Removes the existing generated suites and tests cleaning up the `_generated` directory before the actual run. For example, `generate:tests SampleTest --remove` cleans up the entire `_generated` directory and generates `SampleTest` only. |
119+
| Option | Description|
120+
| ---| --- |
121+
| `--config=[<default> or <singleRun> or <parallel>]` | Creates a single manifest file with a list of all tests. The default location is `tests/functional/Magento/FunctionalTest/_generated/testManifest.txt`.<br/> You can split the list into multiple groups using `--config=parallel`; the groups will be generated in `_generated/groups/` like `_generated/groups/group1.txt, group2.txt, ...`.</br> Available values: `default` (default), `singleRun`(same as `default`), and `parallel`.</br> Example: `generate:tests --config=parallel`. |
122+
| `--force` | Forces test generation, regardless of the module merge order defined in the Magento instance. Example: `generate:tests --force`. |
123+
| `-i,--time` | Set time in minutes to determine the group size when `--config=parallel` is used. The __default value__ is `10`. Example: `generate:tests --config=parallel --time=15`|
124+
| `--tests` | Defines the test configuration as a JSON string.|
125+
| `--debug` | Returns additional debug information (such as the filename where an error occurred) when test generation fails because of an invalid XML schema. This parameter takes extra processing time. Use it after test generation has failed once. |
126+
| `-r,--remove`| Removes the existing generated suites and tests cleaning up the `_generated` directory before the actual run. For example, `generate:tests SampleTest --remove` cleans up the entire `_generated` directory and generates `SampleTest` only.|
126127

127128
#### Examples of the JSON configuration
128129

@@ -131,7 +132,7 @@ The configuration to generate a single test with no suites:
131132
```json
132133
{
133134
"tests":[
134-
"general_test1" //Generate the "general_test1" test.
135+
"general_test1" //Generate the "general_test1" test.
135136
],
136137
"suites": null
137138
}
@@ -141,10 +142,10 @@ The configuration to generate a single test in the suite:
141142

142143
```json
143144
{
144-
"tests": null, // No tests outside the suite configuration will be generated.
145+
"tests": null, // No tests outside the suite configuration will be generated.
145146
"suites":{
146-
"sample":[ // The suite that contains the test.
147-
"suite_test1" // The test to be generated.
147+
"sample":[ // The suite that contains the test.
148+
"suite_test1" // The test to be generated.
148149
]
149150
}
150151
}
@@ -159,11 +160,11 @@ Complex configuration to generate a few non-suite tests, a single test in a suit
159160
"general_test2",
160161
"general_test3"
161162
],
162-
"suites":{ //Go to suites.
163-
"sample":[ //Go to the "sample" suite.
164-
"suite_test1" //Generate the "suite_test1" test.
163+
"suites":{ //Go to suites.
164+
"sample":[ //Go to the "sample" suite.
165+
"suite_test1" //Generate the "suite_test1" test.
165166
],
166-
"sample2":[] //Generate all tests in the "sample2" suite.
167+
"sample2":[] //Generate all tests in the "sample2" suite.
167168
}
168169
}
169170
```
@@ -190,8 +191,8 @@ vendor/bin/mftf generate:suite <suite name> [<suite name>] [--remove]
190191

191192
#### Options
192193

193-
| Option | Description |
194-
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
194+
| Option | Description |
195+
| --- | --- |
195196
| `-r,--remove` | Removes the existing generated suites and tests cleaning up the `_generated` directory before the actual run. For example, `vendor/bin/mftf generate:suite WYSIWYG --remove` cleans up the entire `_generated` directory and generates `WYSIWYG` only. |
196197

197198
#### Example
@@ -253,7 +254,6 @@ vendor/bin/mftf generate:docs [--clean] [--output=/path/to/alternate/dir]
253254
vendor/bin/mftf generate:docs --clean
254255
```
255256

256-
257257
### `reset`
258258

259259
#### Description
@@ -389,6 +389,20 @@ vendor/bin/mftf setup:env
389389

390390
The example parameters are taken from the `etc/config/.env.example` file.
391391

392+
### `static:checks`
393+
394+
Runs all MFTF static:checks on the test codebase that MFTF is currently attached to.
395+
396+
#### Existing static checks
397+
398+
* Test Dependency: Checks that test dependencies do not violate Magento module's composer dependencies.
399+
400+
#### Usage
401+
402+
```bash
403+
vendor/bin/mftf static:checks
404+
```
405+
392406
### `upgrade:tests`
393407

394408
Applies all the MFTF major version upgrade scripts to test components in the given path (`test.xml`, `data.xml`, etc).

docs/tips-tricks.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,27 @@ Use numbers within `stepKeys` when order is important, such as with testing sort
283283

284284
## Selectors
285285

286+
### Use contains() around text()
287+
288+
When possible, use `contains(text(), 'someTextHere')` rather than `text()='someTextHere'`.
289+
`contains()` ignores whitespace while `text()` accounts for it.
290+
291+
**Why?**
292+
If you are comparing text within a selector and have an unexpected space, or a blank line above or below the string, `text()` will fail while the `contains(text())` format will catch it.
293+
In this scenario `text()` is more exacting. Use it when you need to be very precise about what is getting compared.
294+
295+
<span style="color:green">
296+
GOOD:
297+
</span>
298+
299+
`//span[contains(text(), 'SomeTextHere')]`
300+
301+
<span style="color:red">
302+
BAD:
303+
</span>
304+
305+
`//span[text()='SomeTextHere']`
306+
286307
### Build selectors in proper order
287308

288309
When building selectors for form elements, start with the parent context of the form element.
@@ -353,6 +374,31 @@ BAD:
353374

354375
## General tips
355376

377+
### Use data references to avoid hardcoded values
378+
379+
If you need to run a command such as `<magentoCLI command="config:set" />`, do not hardcode paths and values to the command.
380+
Rather, create an appropriate `ConfigData.xml` file, which contains the required parameters for running the command.
381+
It will simplify the future maintanence of tests.
382+
383+
<span style="color:green">
384+
GOOD:
385+
</span>
386+
387+
```xml
388+
<magentoCLI command="config:set {{StorefrontCustomerCaptchaLength3ConfigData.path}} {{StorefrontCustomerCaptchaLength3ConfigData.value}}" stepKey="setCaptchaLength" />
389+
```
390+
391+
<span style="color:red">
392+
BAD:
393+
</span>
394+
395+
```xml
396+
<magentoCLI command="config:set customer/captcha/length 3" stepKey="setCaptchaLength" />
397+
```
398+
399+
For example:
400+
[This test][] refers to this [Data file][].
401+
356402
### Use descriptive variable names
357403

358404
Use descriptive variable names to increase readability.
@@ -398,3 +444,7 @@ BAD:
398444
```
399445

400446
<!--{% endraw %}-->
447+
448+
<!-- Link Definitions -->
449+
[This test]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaRegisterNewCustomerTest.xml#L24
450+
[Data file]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Data/CaptchaConfigData.xml

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ protected function configure()
4646
*
4747
* @param InputInterface $input
4848
* @param OutputInterface $output
49-
* @return integer|null|void
49+
* @return integer
5050
* @throws \Exception
5151
*
5252
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
5353
*/
54-
protected function execute(InputInterface $input, OutputInterface $output)
54+
protected function execute(InputInterface $input, OutputInterface $output): int
5555
{
5656
$tests = $input->getArgument('name');
5757
$skipGeneration = $input->getOption('skip-generate');
@@ -85,7 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8585
$process->setWorkingDirectory(TESTS_BP);
8686
$process->setIdleTimeout(600);
8787
$process->setTimeout(0);
88-
$process->run(
88+
89+
return $process->run(
8990
function ($type, $buffer) use ($output) {
9091
$output->write($buffer);
9192
}

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ protected function configure()
5959
*
6060
* @param InputInterface $input
6161
* @param OutputInterface $output
62-
* @return integer|null|void
62+
* @return integer
6363
* @throws \Exception
6464
*
6565
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
6666
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6767
*/
68-
protected function execute(InputInterface $input, OutputInterface $output)
68+
protected function execute(InputInterface $input, OutputInterface $output): int
6969
{
7070
// Create Mftf Configuration
7171
MftfApplicationConfig::create(
@@ -78,7 +78,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
$testConfiguration = $this->getFailedTestList();
7979

8080
if ($testConfiguration === null) {
81-
return null;
81+
// no failed tests found, run is a success
82+
return 0;
8283
}
8384

8485
$command = $this->getApplication()->find('generate:tests');
@@ -87,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8788
$command->run(new ArrayInput($args), $output);
8889

8990
$testManifestList = $this->readTestManifestFile();
90-
91+
$returnCode = 0;
9192
foreach ($testManifestList as $testCommand) {
9293
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
9394
$codeceptionCommand .= $testCommand;
@@ -96,11 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
9697
$process->setWorkingDirectory(TESTS_BP);
9798
$process->setIdleTimeout(600);
9899
$process->setTimeout(0);
99-
$process->run(
100+
$returnCode = max($returnCode, $process->run(
100101
function ($type, $buffer) use ($output) {
101102
$output->write($buffer);
102103
}
103-
);
104+
));
104105
if (file_exists(self::TESTS_FAILED_FILE)) {
105106
$this->failedList = array_merge(
106107
$this->failedList,
@@ -111,6 +112,8 @@ function ($type, $buffer) use ($output) {
111112
foreach ($this->failedList as $test) {
112113
$this->writeFailedTestToFile($test, self::TESTS_FAILED_FILE);
113114
}
115+
116+
return $returnCode;
114117
}
115118

116119
/**

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ protected function configure()
5353
*
5454
* @param InputInterface $input
5555
* @param OutputInterface $output
56-
* @return integer|null|void
56+
* @return integer
5757
* @throws \Exception
5858
*
5959
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
6060
*/
61-
protected function execute(InputInterface $input, OutputInterface $output)
61+
protected function execute(InputInterface $input, OutputInterface $output): int
6262
{
6363
$skipGeneration = $input->getOption('skip-generate');
6464
$force = $input->getOption('force');
@@ -102,7 +102,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
102102
$process->setWorkingDirectory(TESTS_BP);
103103
$process->setIdleTimeout(600);
104104
$process->setTimeout(0);
105-
$process->run(
105+
106+
return $process->run(
106107
function ($type, $buffer) use ($output) {
107108
$output->write($buffer);
108109
}

0 commit comments

Comments
 (0)