6
6
7
7
namespace Magento \FunctionalTestingFramework \Module ;
8
8
9
+ use Codeception \Events ;
9
10
use Codeception \Module \WebDriver ;
10
11
use Codeception \Test \Descriptor ;
11
12
use Codeception \TestInterface ;
21
22
use Magento \FunctionalTestingFramework \Util \Protocol \CurlInterface ;
22
23
use Magento \Setup \Exception ;
23
24
use Magento \FunctionalTestingFramework \Util \ConfigSanitizerUtil ;
25
+ use Yandex \Allure \Adapter \Event \TestCaseFinishedEvent ;
24
26
use Yandex \Allure \Adapter \Support \AttachmentSupport ;
25
27
26
28
/**
@@ -80,6 +82,27 @@ class MagentoWebDriver extends WebDriver
80
82
LC_MESSAGES => null ,
81
83
];
82
84
85
+ /**
86
+ * Current Test Interface
87
+ *
88
+ * @var TestInterface
89
+ */
90
+ private $ current_test ;
91
+
92
+ /**
93
+ * Png image filepath for current test
94
+ *
95
+ * @var string
96
+ */
97
+ private $ pngReport ;
98
+
99
+ /**
100
+ * Html filepath for current test
101
+ *
102
+ * @var string
103
+ */
104
+ private $ htmlReport ;
105
+
83
106
public function _initialize ()
84
107
{
85
108
$ this ->config = ConfigSanitizerUtil::sanitizeWebDriverConfig ($ this ->config );
@@ -465,22 +488,43 @@ public function assertElementContainsAttribute($selector, $attribute, $value)
465
488
}
466
489
}
467
490
491
+ public function _before (TestInterface $ test )
492
+ {
493
+ $ this ->current_test = $ test ;
494
+ $ this ->htmlReport = null ;
495
+ $ this ->pngReport = null ;
496
+
497
+ parent ::_before ($ test );
498
+ }
499
+
468
500
/**
469
501
* Override for _failed method in Codeception method. Adds png and html attachments to allure report
470
502
* following parent execution of test failure processing.
503
+ *
471
504
* @param TestInterface $test
472
505
* @param \Exception $fail
473
506
*/
474
507
public function _failed (TestInterface $ test , $ fail )
475
508
{
476
- parent ::_failed ($ test , $ fail );
509
+ $ this ->debugWebDriverLogs ($ test );
510
+
511
+ if ($ this ->pngReport == null && $ this ->htmlReport == null ) {
512
+ $ this ->saveScreenshot ();
513
+ }
514
+
515
+ $ this ->addAttachment ($ this ->pngReport , $ test ->getMetadata ()->getName () . '.png ' , 'image/png ' );
516
+ $ this ->addAttachment ($ this ->htmlReport , $ test ->getMetadata ()->getName () . '.html ' , 'text/html ' );
517
+ }
477
518
478
- // Reconstruct file naming from codeception method
519
+ /**
520
+ * Function which saves a screenshot of the current stat of the browser
521
+ */
522
+ public function saveScreenshot ()
523
+ {
524
+ $ test = $ this ->current_test ;
479
525
$ filename = preg_replace ('~\W~ ' , '. ' , Descriptor::getTestSignature ($ test ));
480
526
$ outputDir = codecept_output_dir ();
481
- $ pngReport = $ outputDir . mb_strcut ($ filename , 0 , 245 , 'utf-8 ' ) . '.fail.png ' ;
482
- $ htmlReport = $ outputDir . mb_strcut ($ filename , 0 , 244 , 'utf-8 ' ) . '.fail.html ' ;
483
- $ this ->addAttachment ($ pngReport , $ test ->getMetadata ()->getName () . '.png ' , 'image/png ' );
484
- $ this ->addAttachment ($ htmlReport , $ test ->getMetadata ()->getName () . '.html ' , 'text/html ' );
527
+ $ this ->_saveScreenshot ($ this ->pngReport = $ outputDir . mb_strcut ($ filename , 0 , 245 , 'utf-8 ' ) . '.fail.png ' );
528
+ $ this ->_savePageSource ($ this ->htmlReport = $ outputDir . mb_strcut ($ filename , 0 , 244 , 'utf-8 ' ) . '.fail.html ' );
485
529
}
486
- }
530
+ }
0 commit comments