@@ -59,11 +59,12 @@ class functionalSuiteHooks extends \Codeception\GroupObject
5959 $this->create = new DataPersistenceHandler($createThis, [], $createFields);
6060 $this->create->createEntity();
6161 $webDriver->see("John", msq("uniqueData") . "John");
62-
62+
6363 // reset configuration and close session
6464 $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')->_resetConfig();
6565 $webDriver->webDriver->close();
6666 $webDriver->webDriver = null;
67+
6768 } catch (\Exception $exception) {
6869 $this->preconditionFailure = $exception->getMessage();
6970 }
@@ -74,16 +75,37 @@ class functionalSuiteHooks extends \Codeception\GroupObject
7475
7576 public function _after(\Codeception\Event\TestEvent $e)
7677 {
77- $this->executePostConditions();
78+ $this->executePostConditions($e );
7879 }
7980
8081
81- private function executePostConditions()
82+ private function executePostConditions(\Codeception\Event\TestEvent $e )
8283 {
8384 if ($this->currentTestRun == $this->testCount) {
8485 print sprintf(self::$HOOK_EXECUTION_INIT, "after");
8586
8687 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+ }
87109 $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
88110
89111 // close any open sessions
@@ -97,11 +119,6 @@ class functionalSuiteHooks extends \Codeception\GroupObject
97119 $webDriver->amOnPage("some.url");
98120 $webDriver->deleteEntityByUrl("deleteThis");
99121 $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;
105122 } catch (\Exception $exception) {
106123 print $exception->getMessage();
107124 }
0 commit comments