Skip to content

Commit e99db41

Browse files
committed
MQE-2110: MFTF command to pause test execution
1 parent b620d63 commit e99db41

File tree

9 files changed

+100
-13
lines changed

9 files changed

+100
-13
lines changed

docs/commands/mftf.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,31 @@ To upgrade all test components inside the `Catalog` module:
559559
vendor/bin/mftf upgrade:tests /Users/user/magento2/app/code/Magento/Catalog/Test/Mftf/
560560
```
561561

562+
### `codecept:run`
563+
564+
MFTF wrapper command invokes `vendor/bin/codecept run`. This command runs tests in functional suite. It does not generate tests for you. You must do that first.
565+
566+
#### Usage
567+
568+
See https://codeception.com/docs/reference/Commands#Run
569+
570+
```bash
571+
vendor/bin/mftf codecept:run [<suite|test>] --[<option(s)>]
572+
```
573+
574+
#### Examples
575+
576+
```bash
577+
# Run all tests in functional suite
578+
vendor/bin/mftf codecept:run functional
579+
# Run all tests in functional suite with options
580+
vendor/bin/mftf codecept:run functional --verbose --steps --debug
581+
# Run one test
582+
vendor/bin/mftf codecept:run functional Magento/_generated/default/AdminLoginSuccessfulTestCest
583+
# Run all tests in default group
584+
vendor/bin/mftf codecept:run functional --verbose --steps -g default
585+
```
586+
562587
<!-- LINK DEFINITIONS -->
563588

564589
[configuration]: ../configuration.md

docs/interactive-pause.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Interactive Pause
2+
3+
It’s hard to write a complete test at once. You will need to try different commands with different arguments before you find a correct path.
4+
5+
Since Codeception 3.0 you can pause execution in any point and enter interactive shell where you will be able to try commands in action.
6+
7+
Now this `Interactive Pause` feature is available in MFTF and all you need to do is to set `ENABLE_PAUSE=true` in `.env`.
8+
9+
Check it out at [Codeception website][] for documentation and a video to see `Interactive Pause` in action.
10+
11+
In short, when a test gets to `$I->pause()` step, it stops and shows a console where you can try all available commands with auto-completion, stash commands, and save screenshot, etc.
12+
13+
## Generation Time
14+
15+
A `<pause>` action in xml will always be generated into php regardless if `ENABLE_PAUSE=true` is set or not.
16+
However, when `ENABLE_PAUSE=true` is set, an additional`pause()` action will be generated in `_failed()` hook for a test,
17+
so that the test could pause on failure at run time.
18+
19+
## Execution Time
20+
21+
To use `Interactive Pause` at run time, there are two types of MFTF commands to use.
22+
23+
### MFTF Run Commands
24+
25+
When `ENABLE_PAUSE=true` is set, the following MFTF run commands support `Interactive Pause`.
26+
27+
```bash
28+
vendor/bin/mftf run:group
29+
```
30+
31+
```bash
32+
vendor/bin/mftf run:test
33+
```
34+
35+
```bash
36+
vendor/bin/mftf run:manifest
37+
```
38+
39+
```bash
40+
vendor/bin/mftf run:failed
41+
```
42+
43+
<div class="bs-callout-warning">
44+
Note: MFTF run command's `--debug` option is different from Codeception `--debug` mode option.
45+
</div>
46+
47+
### MFTF Codecept Run Command
48+
49+
You can also use MFTF's wrapper command to run Codeception directly and activate `Interactive Pause` by passing `--debug` option.
50+
You don't need to set `ENABLE_PAUSE=true` for this command.
51+
52+
```bash
53+
vendor/bin/mftf codecept:run --debug
54+
```
55+
56+
## References
57+
58+
[Codeception website](https://codeception.com/docs/02-GettingStarted#Interactive-Pause)

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
class BaseGenerateCommand extends Command
3232
{
3333
const MFTF_NOTICES = "Placeholder text for MFTF notices\n";
34-
const CODECEPT_RUN_COMMAND = 'codecept:run functional ';
34+
const CODECEPT_RUN = 'codecept:run ';
35+
const CODECEPT_RUN_FUNCTIONAL = self::CODECEPT_RUN . 'functional ';
3536

3637
/**
3738
* Enable pause()
@@ -254,15 +255,15 @@ protected function pauseEnabled()
254255
/**
255256
* Runs the bin/mftf codecept:run command and returns exit code
256257
*
257-
* @param string $command
258+
* @param string $commandStr
258259
* @param OutputInterface $output
259260
* @return integer
260261
* @throws \Exception
261262
*/
262-
protected function codeceptRunTest(string $command, OutputInterface $output)
263+
protected function codeceptRunTest(string $commandStr, OutputInterface $output)
263264
{
264-
$input = new StringInput($command);
265-
$command = $this->getApplication()->find('codecept:run');
265+
$input = new StringInput($commandStr);
266+
$command = $this->getApplication()->find(self::CODECEPT_RUN);
266267
return $command->run($input, $output);
267268
}
268269
}

src/Magento/FunctionalTestingFramework/Console/CodeceptRunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function configure()
2424
{
2525
$this->setName('codecept:run')
2626
->setDescription(
27-
"Wrapper command to codecept:run. See https://codeception.com/docs/reference/Commands"
27+
"Wrapper command to vendor/bin/codecept:run. See https://codeception.com/docs/reference/Commands#Run"
2828
);
2929

3030
parent::configure();

src/Magento/FunctionalTestingFramework/Console/RunManifestCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111
private function runManifestLine(string $manifestLine, OutputInterface $output)
112112
{
113113
if (getenv('ENABLE_PAUSE') === 'true') {
114-
$codeceptionCommand = BaseGenerateCommand::CODECEPT_RUN_COMMAND
115-
. '--verbose --steps --debug' . $manifestLine;
114+
$codeceptionCommand = BaseGenerateCommand::CODECEPT_RUN_FUNCTIONAL
115+
. '--verbose --steps --debug ' . $manifestLine;
116116
$input = new StringInput($codeceptionCommand);
117117
$command = $this->getApplication()->find('codecept:run');
118118
$subReturnCode = $command->run($input, $output);

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124124
private function runTests(array $tests, OutputInterface $output)
125125
{
126126
if ($this->pauseEnabled()) {
127-
$codeceptionCommand = self::CODECEPT_RUN_COMMAND;
127+
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL;
128128
} else {
129129
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
130130
}
@@ -164,7 +164,7 @@ private function runTests(array $tests, OutputInterface $output)
164164
private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
165165
{
166166
if ($this->pauseEnabled()) {
167-
$codeceptionCommand = self::CODECEPT_RUN_COMMAND . '--verbose --steps --debug';
167+
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug';
168168
} else {
169169
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept')
170170
. ' run functional --verbose --steps ';

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
118118
$returnCode = 0;
119119
foreach ($testManifestList as $testCommand) {
120120
if ($this->pauseEnabled()) {
121-
$codeceptionCommand = self::CODECEPT_RUN_COMMAND . $testCommand . ' --debug';
122-
$this->codeceptRunTest($codeceptionCommand, $output);
121+
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . $testCommand . ' --debug';
122+
$returnCode = $this->codeceptRunTest($codeceptionCommand, $output);
123123
} else {
124124
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
125125
$codeceptionCommand .= $testCommand;

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9595
}
9696

9797
if ($this->pauseEnabled()) {
98-
$commandString = self::CODECEPT_RUN_COMMAND . '--verbose --steps --debug';
98+
$commandString = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug';
9999
} else {
100100
$commandString = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional --verbose --steps';
101101
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,9 @@ public function _failed(TestInterface $test, $fail)
836836

837837
if ($this->pngReport === null && $this->htmlReport === null) {
838838
$this->saveScreenshot();
839+
if (getenv('ENABLE_PAUSE') === 'true') {
840+
$this->pause();
841+
}
839842
}
840843

841844
if ($this->current_test == null) {

0 commit comments

Comments
 (0)