@@ -6,6 +6,11 @@ use Facebook\WebDriver\Remote\RemoteWebDriver;
66use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
77use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
88use Magento\FunctionalTestingFramework\Module\MagentoWebDriver;
9+ use Magento\FunctionalTestingFramework\Module\MagentoAssert;
10+ use Magento\FunctionalTestingFramework\Module\MagentoActionProxies;
11+ use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
12+ use Codeception\Lib\ModuleContainer;
13+ use Codeception\Module;
914
1015/**
1116 * Group class is Codeception Extension which is allowed to handle to all internal events.
@@ -24,9 +29,15 @@ class functionalSuiteHooks extends \Codeception\GroupObject
2429 private $currentTestRun = 0;
2530 private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of functionalSuiteHooks suite %s block ********/\n";
2631 private static $HOOK_EXECUTION_END = "\n/******** Execution of functionalSuiteHooks suite %s block complete ********/\n";
32+ /** @var MagentoWebDriver */
33+ private $webDriver;
34+ /** @var ModuleContainer */
35+ private $moduleContainer;
2736
2837 public function _before(\Codeception\Event\TestEvent $e)
2938 {
39+ $this->webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
40+ $this->moduleContainer = $this->webDriver->getModuleContainer();
3041 // increment test count per execution
3142 $this->currentTestRun++;
3243 $this->executePreConditions();
@@ -37,22 +48,18 @@ class functionalSuiteHooks extends \Codeception\GroupObject
3748 }
3849 }
3950
40-
4151 private function executePreConditions()
4252 {
4353 if ($this->currentTestRun == 1) {
4454 print sprintf(self::$HOOK_EXECUTION_INIT, "before");
4555
46- /** @var MagentoWebDriver $webDriver */
47- $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
48-
4956 try {
50- if ($webDriver->webDriver != null) {
51- $webDriver->_restart();
57+ if ($this-> webDriver->webDriver != null) {
58+ $this-> webDriver->_restart();
5259 } else {
53- $webDriver->_initializeSession();
60+ $this-> webDriver->_initializeSession();
5461 }
55- $webDriver ->amOnPage("some.url"); // stepKey: before
62+ $this->getModuleForAction("amOnPage") ->amOnPage("some.url"); // stepKey: before
5663 $createOneFields['someKey'] = "dataHere";
5764 PersistedObjectHandler::getInstance()->createEntity(
5865 "createOne",
@@ -79,18 +86,18 @@ class functionalSuiteHooks extends \Codeception\GroupObject
7986 "createEntityFour",
8087 ["createEntityTwo", "createEntityThree"]
8188 );
82- $webDriver ->click(PersistedObjectHandler::getInstance()->retrieveEntityField('createTwo', 'data', 'suite')); // stepKey: clickWithData
89+ $this->getModuleForAction("click") ->click(PersistedObjectHandler::getInstance()->retrieveEntityField('createTwo', 'data', 'suite')); // stepKey: clickWithData
8390 print("Entering Action Group [AC] actionGroupWithTwoArguments");
84- $webDriver ->see("John", msq("uniqueData") . "John"); // stepKey: seeFirstNameAC
91+ $this->getModuleForAction("see") ->see("John", msq("uniqueData") . "John"); // stepKey: seeFirstNameAC
8592 print("Exiting Action Group [AC] actionGroupWithTwoArguments");
8693 } catch (\Exception $exception) {
8794 $this->preconditionFailure = $exception->getMessage();
8895 }
8996
9097 // reset configuration and close session
91- $webDriver->_resetConfig();
92- $webDriver->webDriver->close();
93- $webDriver->webDriver = null;
98+ $this-> webDriver->_resetConfig();
99+ $this-> webDriver->webDriver->close();
100+ $this-> webDriver->webDriver = null;
94101
95102 print sprintf(self::$HOOK_EXECUTION_END, "before");
96103 }
@@ -101,15 +108,11 @@ class functionalSuiteHooks extends \Codeception\GroupObject
101108 $this->executePostConditions($e);
102109 }
103110
104-
105111 private function executePostConditions(\Codeception\Event\TestEvent $e)
106112 {
107113 if ($this->currentTestRun == $this->testCount) {
108114 print sprintf(self::$HOOK_EXECUTION_INIT, "after");
109115
110- /** @var MagentoWebDriver $webDriver */
111- $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
112-
113116 try {
114117 // Find out if Test in Suite failed, will cause potential failures in suite after
115118 $cest = $e->getTest();
@@ -132,23 +135,23 @@ class functionalSuiteHooks extends \Codeception\GroupObject
132135 }
133136 }
134137 }
135- if ($webDriver->webDriver != null) {
136- $webDriver->_restart();
138+ if ($this-> webDriver->webDriver != null) {
139+ $this-> webDriver->_restart();
137140 } else {
138- $webDriver->_initializeSession();
141+ $this-> webDriver->_initializeSession();
139142 }
140- $webDriver ->amOnPage("some.url"); // stepKey: after
141- $webDriver ->deleteEntityByUrl("deleteThis"); // stepKey: delete
143+ $this->getModuleForAction("amOnPage") ->amOnPage("some.url"); // stepKey: after
144+ $this->getModuleForAction("deleteEntityByUrl") ->deleteEntityByUrl("deleteThis"); // stepKey: delete
142145 print("Entering Action Group [AC] actionGroupWithTwoArguments");
143- $webDriver ->see("John", msq("uniqueData") . "John"); // stepKey: seeFirstNameAC
146+ $this->getModuleForAction("see") ->see("John", msq("uniqueData") . "John"); // stepKey: seeFirstNameAC
144147 print("Exiting Action Group [AC] actionGroupWithTwoArguments");
145148 } catch (\Exception $exception) {
146149 print $exception->getMessage();
147150 }
148151
149152 PersistedObjectHandler::getInstance()->clearSuiteObjects();
150153
151- $this->closeSession($webDriver);
154+ $this->closeSession($this-> webDriver);
152155
153156 print sprintf(self::$HOOK_EXECUTION_END, "after");
154157 }
@@ -158,13 +161,12 @@ class functionalSuiteHooks extends \Codeception\GroupObject
158161 * Close session method closes current session.
159162 * If config 'close_all_sessions' is set to 'true' all sessions will be closed.
160163 *
161- * @param MagentoWebDriver $webDriver
162164 * return void
163165 */
164- private function closeSession(MagentoWebDriver $webDriver ): void
166+ private function closeSession(): void
165167 {
166- $webDriverConfig = $webDriver->_getConfig();
167- $webDriver->_closeSession();
168+ $webDriverConfig = $this-> webDriver->_getConfig();
169+ $this-> webDriver->_closeSession();
168170 if (isset($webDriverConfig['close_all_sessions']) && $webDriverConfig['close_all_sessions'] === "true") {
169171 $wdHost = sprintf(
170172 '%s://%s:%s%s',
@@ -180,4 +182,20 @@ class functionalSuiteHooks extends \Codeception\GroupObject
180182 }
181183 }
182184 }
185+
186+ /**
187+ * Return the module for an action.
188+ *
189+ * @param string $action
190+ * @return Module
191+ * @throws \Exception
192+ */
193+ private function getModuleForAction($action)
194+ {
195+ $module = $this->moduleContainer->moduleForAction($action);
196+ if ($module === null) {
197+ throw new TestFrameworkException('Invalid action "' . $action . '"' . PHP_EOL);
198+ }
199+ return $module;
200+ }
183201}
0 commit comments