Skip to content

Commit ef67fe2

Browse files
authored
Merge branch 'develop' into MQE-1685
2 parents 4a055bf + ac49cbe commit ef67fe2

File tree

17 files changed

+437
-51
lines changed

17 files changed

+437
-51
lines changed

dev/tests/_bootstrap.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
$kernel = \AspectMock\Kernel::getInstance();
1818
$kernel->init([
1919
'debug' => true,
20-
'includePaths' => [PROJECT_ROOT . DIRECTORY_SEPARATOR . 'src'],
20+
'includePaths' => [
21+
PROJECT_ROOT . DIRECTORY_SEPARATOR . 'src',
22+
PROJECT_ROOT . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'allure-framework'
23+
],
2124
'cacheDir' => PROJECT_ROOT .
2225
DIRECTORY_SEPARATOR .
2326
'dev' .
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestingFramework\Allure;
7+
8+
use Magento\FunctionalTestingFramework\Allure\AllureHelper;
9+
use Yandex\Allure\Adapter\Allure;
10+
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
11+
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
12+
use Yandex\Allure\Adapter\Event\StepStartedEvent;
13+
use Yandex\Allure\Adapter\Model\Attachment;
14+
use AspectMock\Test as AspectMock;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class AllureHelperTest extends TestCase
18+
{
19+
const MOCK_FILENAME = 'filename';
20+
21+
/**
22+
* Clear Allure Lifecycle
23+
*/
24+
public function tearDown()
25+
{
26+
Allure::setDefaultLifecycle();
27+
}
28+
29+
/**
30+
* AddAtachmentToStep should add an attachment to the current step
31+
* @throws \Yandex\Allure\Adapter\AllureException
32+
*/
33+
public function testAddAttachmentToStep()
34+
{
35+
$this->mockAttachmentWriteEvent();
36+
$expectedData = "string";
37+
$expectedCaption = "caption";
38+
39+
//Prepare Allure lifecycle
40+
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
41+
42+
//Call function
43+
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
44+
45+
// Assert Attachment is created as expected
46+
$step = Allure::lifecycle()->getStepStorage()->pollLast();
47+
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null);
48+
$this->assertEquals($step->getAttachments()[0], $expectedAttachment);
49+
}
50+
51+
/**
52+
* AddAttachmentToLastStep should add an attachment only to the last step
53+
* @throws \Yandex\Allure\Adapter\AllureException
54+
*/
55+
public function testAddAttachmentToLastStep()
56+
{
57+
$this->mockAttachmentWriteEvent();
58+
$expectedData = "string";
59+
$expectedCaption = "caption";
60+
61+
//Prepare Allure lifecycle
62+
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
63+
Allure::lifecycle()->fire(new StepFinishedEvent('firstStep'));
64+
Allure::lifecycle()->fire(new StepStartedEvent('secondStep'));
65+
Allure::lifecycle()->fire(new StepFinishedEvent('secondStep'));
66+
67+
//Call function
68+
AllureHelper::addAttachmentToLastStep($expectedData, $expectedCaption);
69+
70+
//Continue Allure lifecycle
71+
Allure::lifecycle()->fire(new StepStartedEvent('thirdStep'));
72+
Allure::lifecycle()->fire(new StepFinishedEvent('thirdStep'));
73+
74+
// Assert Attachment is created as expected on the right step
75+
$rootStep = Allure::lifecycle()->getStepStorage()->pollLast();
76+
77+
$firstStep = $rootStep->getSteps()[0];
78+
$secondStep = $rootStep->getSteps()[1];
79+
$thirdStep = $rootStep->getSteps()[2];
80+
81+
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null);
82+
$this->assertEmpty($firstStep->getAttachments());
83+
$this->assertEquals($secondStep->getAttachments()[0], $expectedAttachment);
84+
$this->assertEmpty($thirdStep->getAttachments());
85+
}
86+
87+
/**
88+
* Mock file system manipulation function
89+
* @throws \Exception
90+
*/
91+
public function mockAttachmentWriteEvent()
92+
{
93+
AspectMock::double(AddAttachmentEvent::class, [
94+
"getAttachmentFileName" => self::MOCK_FILENAME
95+
]);
96+
}
97+
}

docs/commands/mftf.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ vendor/bin/mftf run:test LoginAsAdminTest LoginAsCustomerTest -r
5858

5959
This command cleans up the previously generated tests; generates and runs the `LoginAsAdminTest` and `LoginAsCustomerTest` tests.
6060

61+
### Generate and run a testManifest.txt file
62+
63+
```bash
64+
vendor/bin/mftf run:manifest path/to/your/testManifest.txt
65+
```
66+
67+
This command runs all tests specified in a `testManifest.txt` file. When you generate tests, a `testManifest.txt` file is also generated for you. You can pass this file directly to the `run:manifest` command and it will execute all listed tests. You can also create your own file in the same format to execute a subset of tests. Note: This command does not generate tests.
68+
6169
### Generate and run previously failed tests
6270

6371
```bash
@@ -338,6 +346,30 @@ Generate the `LoginCustomerTest` and `StorefrontCreateCustomerTest` tests from X
338346
vendor/bin/mftf run:test LoginCustomerTest StorefrontCreateCustomerTest
339347
```
340348

349+
### `run:manifest`
350+
351+
Runs a testManifest.txt file.
352+
353+
This command runs all tests specified in a testManifest.xml file. It does not generate tests for you. You must do that as first.
354+
355+
#### Usage
356+
357+
```bash
358+
vendor/bin/mftf run:manifest path/to/your/testManifest.txt
359+
```
360+
361+
#### Example testManifest.xml file
362+
363+
Each line should contain either: one test path or one group (-g) reference.
364+
365+
```
366+
tests/functional/tests/MFTF/_generated/default/AdminLoginTestCest.php
367+
-g PaypalTestSuite
368+
tests/functional/tests/MFTF/_generated/default/SomeOtherTestCest.php
369+
tests/functional/tests/MFTF/_generated/default/ThirdTestCest.php
370+
-g SomeOtherSuite
371+
```
372+
341373
### `run:failed`
342374

343375
Regenerates and reruns tests that previously failed.

docs/reporting.md

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The `mftf` tool logs output continuously to the `dev/tests/acceptance/mftf.log`
1818

1919
## Command line
2020

21-
The MFTF reports about its progress during test run when you run the `mftf` CLI tool with [`run:test`][] or [`run:group`][] commands.
21+
MFTF reports about its progress during test run when you run the `mftf` CLI tool with [`run:test`][] or [`run:group`][] commands.
2222

2323
The report can contain three main parts:
2424

@@ -35,14 +35,7 @@ The following sections demonstrate an example interpretation of a complete log s
3535

3636
### Pre-run check report
3737

38-
First, the MFTF reports about issues with environment.
39-
In our case, there is an issue with PHP library loading.
40-
41-
```terminal
42-
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20160303/php_intl.dll' - dlopen(/usr/local/lib/php/pecl/20160303/php_intl.dll, 9): image not found in Unknown on line 0
43-
```
44-
45-
Next, the MFTF returns `DEPRECATION` reports alerting you that required test components are missing in XML test definitions.
38+
First, MFTF returns `DEPRECATION` warnings alerting you that required test components are missing in XML test definitions.
4639

4740
```terminal
4841
DEPRECATION: Test AdminFilteringCategoryProductsUsingScopeSelectorTest is missing required annotations.{"testName":"AdminFilteringCategoryProductsUsingScopeSelectorTest","missingAnnotations":"stories"}
@@ -51,7 +44,7 @@ DEPRECATION: Test AdminRemoveProductWeeeAttributeOptionTest is missing required
5144
Generate Tests Command Run
5245
```
5346

54-
`Generate Tests Command Run` indicates the moment when the MFTF has run the tests generation command actually.
47+
`Generate Tests Command Run` indicates that test generation is finished and tests are able to be executed.
5548

5649
### Test execution report
5750

@@ -72,7 +65,7 @@ Magento\FunctionalTestingFramework.functional Tests (2) ------------------------
7265
Modules: \Magento\FunctionalTestingFramework\Module\MagentoWebDriver, \Magento\FunctionalTestingFramework\Helper\Acceptance, \Magento\FunctionalTestingFramework\Helper\MagentoFakerData, \Magento\FunctionalTestingFramework\Module\MagentoRestDriver, PhpBrowser, \Magento\FunctionalTestingFramework\Module\MagentoSequence, \Magento\FunctionalTes
7366
```
7467

75-
After the test generation command (mentioned in the previous section), the MFTF delegates control to the `vendor/codeception` tool, which is the `Codeception PHP Testing Framework` of version `2.3.9` that uses `PHPUnit` of version `6.5.13`.
68+
After the test generation command (mentioned in the previous section), MFTF delegates control to the `vendor/codeception` tool, which is the `Codeception PHP Testing Framework` of version `2.3.9` that uses `PHPUnit` of version `6.5.13`.
7669

7770
The tool runs `2 Tests` using the configuration defined in the `functional` suite under the `Magento\FunctionalTestingFramework` namespace.
7871
The corresponding configuration file is `acceptance/tests/functional.suite.yml`.
@@ -154,7 +147,7 @@ I save screenshot
154147
FAIL
155148
```
156149

157-
When a test step fails, the MFTF always saves a screenshot of the web page with the failing state immediately after the failure occurs.
150+
When a test step fails, MFTF always saves a screenshot of the web page with the failing state immediately after the failure occurs.
158151
`I save screenshot` follows the failing test step `I see "#something"` in our case.
159152

160153
A screenshot of the fail goes at the `acceptance/tests/_output` directory in both PNG and HTML formats:
@@ -176,7 +169,7 @@ Actions after `FAIL` are run as a part of the [`after`][] hook of the test.
176169

177170
### Test result report
178171

179-
After the MFTF completed test execution, it generates a general report about test results along with detailed information about each fail.
172+
After MFTF completed test execution, it generates a general report about test results along with detailed information about each fail.
180173

181174
```terminal
182175
--------------------------------------------------------------------------------
@@ -192,7 +185,7 @@ First you see warnings and deprecations.
192185
The `DEPRECATION` here is thrown by an MFTF dependency (Symfony) that is out of the scope for test writers and should be considered by MFTF contributors.
193186
If you encounter this type of reporting, [report an issue][].
194187

195-
Then, the MFTF reports that the test run took 52.43 seconds using 16 MB of system RAM.
188+
Then, MFTF reports that the test run took 52.43 seconds using 16 MB of system RAM.
196189
And, finally, that there was `1 failure`.
197190

198191
Next, the report provides details about the test failure.
@@ -268,19 +261,25 @@ FAILURES!
268261
Tests: 2, Assertions: 3, Failures: 1.
269262
```
270263

271-
The MFTF encountered failures due to the last test run, that included *2* tests with *3* assertions.
264+
MFTF encountered failures due to the last test run, that included *2* tests with *3* assertions.
272265
*1* assertion fails.
273266

274267
## Allure
275268

276-
Each time you run tests, the MFTF appends an XML file with results at the `tests/_output/allure-results/` directory.
269+
Each time you run tests, MFTF appends an XML file with results at the `tests/_output/allure-results/` directory.
277270

278271
The official [Allure Test Report][] documentation is well-covered, so we'll list only the CLI commands that you would need for your day-to-day work.
279272

280273
<div class="bs-callout bs-callout-info">
281274
The following commands are relative to the Magento installation directory.
282275
</div>
283276

277+
To generate the HTML Allure report in a temporary folder and open the report in your default web browser:
278+
279+
```bash
280+
allure serve dev/tests/acceptance/tests/_output/allure-results/
281+
```
282+
284283
To generate a report to the `allure-report/` at the current directory:
285284

286285
```bash
@@ -334,12 +333,6 @@ To clean up existing reports before generation (for example after getting new re
334333
allure generate dev/tests/acceptance/tests/_output/allure-result --clean
335334
```
336335

337-
To generate the HTML Allure report in a temporary folder and open the report in your default web browser:
338-
339-
```bash
340-
allure serve dev/tests/acceptance/tests/_output/allure-results/
341-
```
342-
343336
Refer to the [Reporting section][] for more Allure CLI details.
344337

345338
<!-- Link definitions -->
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\FunctionalTestingFramework\Allure;
7+
8+
use Yandex\Allure\Adapter\Allure;
9+
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
10+
11+
class AllureHelper
12+
{
13+
/**
14+
* Adds attachment to the current step
15+
* @param mixed $data
16+
* @param string $caption
17+
* @throws \Yandex\Allure\Adapter\AllureException
18+
* @return void
19+
*/
20+
public static function addAttachmentToCurrentStep($data, $caption)
21+
{
22+
Allure::lifecycle()->fire(new AddAttachmentEvent($data, $caption));
23+
}
24+
25+
/**
26+
* Adds Attachment to the last executed step.
27+
* Use this when adding attachments outside of an $I->doSomething() step/context.
28+
* @param mixed $data
29+
* @param string $caption
30+
* @return void
31+
*/
32+
public static function addAttachmentToLastStep($data, $caption)
33+
{
34+
$rootStep = Allure::lifecycle()->getStepStorage()->getLast();
35+
$trueLastStep = array_last($rootStep->getSteps());
36+
37+
$attachmentEvent = new AddAttachmentEvent($data, $caption);
38+
$attachmentEvent->process($trueLastStep);
39+
}
40+
}

src/Magento/FunctionalTestingFramework/Console/CommandList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct(array $commands = [])
3737
'run:test' => new RunTestCommand(),
3838
'run:group' => new RunTestGroupCommand(),
3939
'run:failed' => new RunTestFailedCommand(),
40+
'run:manifest' => new RunManifestCommand(),
4041
'setup:env' => new SetupEnvCommand(),
4142
'upgrade:tests' => new UpgradeTestsCommand(),
4243
'generate:docs' => new GenerateDocsCommand(),

0 commit comments

Comments
 (0)