@@ -59,11 +59,12 @@ class functionalSuiteHooks extends \Codeception\GroupObject
59
59
$this->create = new DataPersistenceHandler($createThis, [], $createFields);
60
60
$this->create->createEntity();
61
61
$webDriver->see("John", msq("uniqueData") . "John");
62
-
62
+
63
63
// reset configuration and close session
64
64
$this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')->_resetConfig();
65
65
$webDriver->webDriver->close();
66
66
$webDriver->webDriver = null;
67
+
67
68
} catch (\Exception $exception) {
68
69
$this->preconditionFailure = $exception->getMessage();
69
70
}
@@ -74,16 +75,37 @@ class functionalSuiteHooks extends \Codeception\GroupObject
74
75
75
76
public function _after(\Codeception\Event\TestEvent $e)
76
77
{
77
- $this->executePostConditions();
78
+ $this->executePostConditions($e );
78
79
}
79
80
80
81
81
- private function executePostConditions()
82
+ private function executePostConditions(\Codeception\Event\TestEvent $e )
82
83
{
83
84
if ($this->currentTestRun == $this->testCount) {
84
85
print sprintf(self::$HOOK_EXECUTION_INIT, "after");
85
86
86
87
try {
88
+ // Find out if Test in Suite failed, will cause potential failures in suite after
89
+ $cest = $e->getTest();
90
+
91
+ //Access private TestResultObject to find stack and if there are any errors (as opposed to failures)
92
+ $testResultObject = call_user_func(\Closure::bind(
93
+ function () use ($cest) {
94
+ return $cest->getTestResultObject();
95
+ },
96
+ $cest
97
+ ));
98
+ $errors = $testResultObject->errors();
99
+
100
+ if (!empty($errors)) {
101
+ foreach ($errors as $error) {
102
+ if ($error->failedTest()->getTestMethod() == $cest->getName()) {
103
+ // Do not attempt to run _after if failure was in the _after block
104
+ // Try to run _after but catch exceptions to prevent them from overwriting original failure.
105
+ print("LAST TEST IN SUITE FAILED, TEST AFTER MAY NOT BE SUCCESSFUL\n");
106
+ }
107
+ }
108
+ }
87
109
$webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
88
110
89
111
// close any open sessions
@@ -97,11 +119,6 @@ class functionalSuiteHooks extends \Codeception\GroupObject
97
119
$webDriver->amOnPage("some.url");
98
120
$webDriver->deleteEntityByUrl("deleteThis");
99
121
$webDriver->see("John", msq("uniqueData") . "John");
100
-
101
- // reset configuration and close session
102
- $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')->_resetConfig();
103
- $webDriver->webDriver->close();
104
- $webDriver->webDriver = null;
105
122
} catch (\Exception $exception) {
106
123
print $exception->getMessage();
107
124
}
0 commit comments