@@ -6,6 +6,11 @@ use Facebook\WebDriver\Remote\RemoteWebDriver;
6
6
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
7
7
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
8
8
use 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;
9
14
10
15
/**
11
16
* Group class is Codeception Extension which is allowed to handle to all internal events.
@@ -24,9 +29,15 @@ class functionalSuiteHooks extends \Codeception\GroupObject
24
29
private $currentTestRun = 0;
25
30
private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of functionalSuiteHooks suite %s block ********/\n";
26
31
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;
27
36
28
37
public function _before(\Codeception\Event\TestEvent $e)
29
38
{
39
+ $this->webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
40
+ $this->moduleContainer = $this->webDriver->getModuleContainer();
30
41
// increment test count per execution
31
42
$this->currentTestRun++;
32
43
$this->executePreConditions();
@@ -37,22 +48,18 @@ class functionalSuiteHooks extends \Codeception\GroupObject
37
48
}
38
49
}
39
50
40
-
41
51
private function executePreConditions()
42
52
{
43
53
if ($this->currentTestRun == 1) {
44
54
print sprintf(self::$HOOK_EXECUTION_INIT, "before");
45
55
46
- /** @var MagentoWebDriver $webDriver */
47
- $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
48
-
49
56
try {
50
- if ($webDriver->webDriver != null) {
51
- $webDriver->_restart();
57
+ if ($this-> webDriver->webDriver != null) {
58
+ $this-> webDriver->_restart();
52
59
} else {
53
- $webDriver->_initializeSession();
60
+ $this-> webDriver->_initializeSession();
54
61
}
55
- $webDriver ->amOnPage("some.url"); // stepKey: before
62
+ $this->getModuleForAction("amOnPage") ->amOnPage("some.url"); // stepKey: before
56
63
$createOneFields['someKey'] = "dataHere";
57
64
PersistedObjectHandler::getInstance()->createEntity(
58
65
"createOne",
@@ -79,18 +86,18 @@ class functionalSuiteHooks extends \Codeception\GroupObject
79
86
"createEntityFour",
80
87
["createEntityTwo", "createEntityThree"]
81
88
);
82
- $webDriver ->click(PersistedObjectHandler::getInstance()->retrieveEntityField('createTwo', 'data', 'suite')); // stepKey: clickWithData
89
+ $this->getModuleForAction("click") ->click(PersistedObjectHandler::getInstance()->retrieveEntityField('createTwo', 'data', 'suite')); // stepKey: clickWithData
83
90
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
85
92
print("Exiting Action Group [AC] actionGroupWithTwoArguments");
86
93
} catch (\Exception $exception) {
87
94
$this->preconditionFailure = $exception->getMessage();
88
95
}
89
96
90
97
// 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;
94
101
95
102
print sprintf(self::$HOOK_EXECUTION_END, "before");
96
103
}
@@ -101,15 +108,11 @@ class functionalSuiteHooks extends \Codeception\GroupObject
101
108
$this->executePostConditions($e);
102
109
}
103
110
104
-
105
111
private function executePostConditions(\Codeception\Event\TestEvent $e)
106
112
{
107
113
if ($this->currentTestRun == $this->testCount) {
108
114
print sprintf(self::$HOOK_EXECUTION_INIT, "after");
109
115
110
- /** @var MagentoWebDriver $webDriver */
111
- $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
112
-
113
116
try {
114
117
// Find out if Test in Suite failed, will cause potential failures in suite after
115
118
$cest = $e->getTest();
@@ -132,23 +135,23 @@ class functionalSuiteHooks extends \Codeception\GroupObject
132
135
}
133
136
}
134
137
}
135
- if ($webDriver->webDriver != null) {
136
- $webDriver->_restart();
138
+ if ($this-> webDriver->webDriver != null) {
139
+ $this-> webDriver->_restart();
137
140
} else {
138
- $webDriver->_initializeSession();
141
+ $this-> webDriver->_initializeSession();
139
142
}
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
142
145
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
144
147
print("Exiting Action Group [AC] actionGroupWithTwoArguments");
145
148
} catch (\Exception $exception) {
146
149
print $exception->getMessage();
147
150
}
148
151
149
152
PersistedObjectHandler::getInstance()->clearSuiteObjects();
150
153
151
- $this->closeSession($webDriver);
154
+ $this->closeSession($this-> webDriver);
152
155
153
156
print sprintf(self::$HOOK_EXECUTION_END, "after");
154
157
}
@@ -158,13 +161,12 @@ class functionalSuiteHooks extends \Codeception\GroupObject
158
161
* Close session method closes current session.
159
162
* If config 'close_all_sessions' is set to 'true' all sessions will be closed.
160
163
*
161
- * @param MagentoWebDriver $webDriver
162
164
* return void
163
165
*/
164
- private function closeSession(MagentoWebDriver $webDriver ): void
166
+ private function closeSession(): void
165
167
{
166
- $webDriverConfig = $webDriver->_getConfig();
167
- $webDriver->_closeSession();
168
+ $webDriverConfig = $this-> webDriver->_getConfig();
169
+ $this-> webDriver->_closeSession();
168
170
if (isset($webDriverConfig['close_all_sessions']) && $webDriverConfig['close_all_sessions'] === "true") {
169
171
$wdHost = sprintf(
170
172
'%s://%s:%s%s',
@@ -180,4 +182,20 @@ class functionalSuiteHooks extends \Codeception\GroupObject
180
182
}
181
183
}
182
184
}
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
+ }
183
201
}
0 commit comments