1 | <?php |
||
14 | class TqContext extends RawTqContext |
||
15 | { |
||
16 | use LogicalAssertion; |
||
17 | |||
18 | /** |
||
19 | * The name and working element of main window. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $mainWindow = []; |
||
24 | /** |
||
25 | * @var string[] |
||
26 | */ |
||
27 | private static $featureTags = []; |
||
28 | /** |
||
29 | * @var Database |
||
30 | */ |
||
31 | private static $database; |
||
32 | |||
33 | /** |
||
34 | * Supports switching between the two windows only. |
||
35 | * |
||
36 | * @Given /^(?:|I )switch to opened window$/ |
||
37 | * @Then /^(?:|I )switch back to main window$/ |
||
38 | */ |
||
39 | public function iSwitchToWindow() |
||
59 | |||
60 | /** |
||
61 | * @Given /^(?:|I )switch to CKFinder window$/ |
||
62 | * |
||
63 | * @javascript |
||
64 | */ |
||
65 | public function switchToCKFinderWindow() |
||
74 | |||
75 | /** |
||
76 | * @param string $name |
||
77 | * An iframe name (null for switching back). |
||
78 | * |
||
79 | * @Given /^(?:|I )switch to an iframe "([^"]*)"$/ |
||
80 | * @Then /^(?:|I )switch back from an iframe$/ |
||
81 | */ |
||
82 | public function iSwitchToAnIframe($name = null) |
||
86 | |||
87 | /** |
||
88 | * Open the page with specified resolution. |
||
89 | * |
||
90 | * @param string $width_height |
||
91 | * String that satisfy the condition "<WIDTH>x<HEIGHT>". |
||
92 | * |
||
93 | * @example |
||
94 | * Given I should use the "1280x800" resolution |
||
95 | * |
||
96 | * @Given /^(?:|I should )use the "([^"]*)" screen resolution$/ |
||
97 | */ |
||
98 | public function useScreenResolution($width_height) |
||
104 | |||
105 | /** |
||
106 | * @param string $action |
||
107 | * The next actions can be: "press", "click", "double click" and "right click". |
||
108 | * @param string $selector |
||
109 | * CSS, inaccurate text or selector name from behat.yml can be used. |
||
110 | * |
||
111 | * @throws \WebDriver\Exception\NoSuchElement |
||
112 | * When element was not found. |
||
113 | * |
||
114 | * @Given /^(?:|I )((?:|(?:double|right) )click|press) on "([^"]*)"$/ |
||
115 | */ |
||
116 | public function pressElement($action, $selector) |
||
124 | |||
125 | /** |
||
126 | * @Given /^(?:|I )wait until AJAX is finished$/ |
||
127 | * |
||
128 | * @javascript |
||
129 | */ |
||
130 | public function waitUntilAjaxIsFinished() |
||
134 | |||
135 | /** |
||
136 | * @param string $selector |
||
137 | * CSS selector or region name. |
||
138 | * |
||
139 | * @Then /^(?:|I )work with elements in "([^"]*)"(?:| region)$/ |
||
140 | */ |
||
141 | public function workWithElementsInRegion($selector) |
||
151 | |||
152 | /** |
||
153 | * @Then /^(?:|I )checkout to whole page$/ |
||
154 | */ |
||
155 | public function unsetWorkingElementScope() |
||
159 | |||
160 | /** |
||
161 | * @param int $seconds |
||
162 | * Amount of seconds when nothing to happens. |
||
163 | * |
||
164 | * @Given /^(?:|I )wait (\d+) seconds$/ |
||
165 | */ |
||
166 | public function waitSeconds($seconds) |
||
170 | |||
171 | /** |
||
172 | * @param string $selector |
||
173 | * Text or CSS. |
||
174 | * |
||
175 | * @throws \Exception |
||
176 | * |
||
177 | * @Given /^(?:|I )scroll to "([^"]*)" element$/ |
||
178 | * |
||
179 | * @javascript |
||
180 | */ |
||
181 | public function scrollToElement($selector) |
||
189 | |||
190 | /** |
||
191 | * @param string $message |
||
192 | * JS error. |
||
193 | * @param bool $negate |
||
194 | * Whether page should or should not contain the error. |
||
195 | * @param string $file |
||
196 | * File where error appears. |
||
197 | * |
||
198 | * @throws \RuntimeException |
||
199 | * @throws \Exception |
||
200 | * |
||
201 | * @example |
||
202 | * Then check that "TypeError: cell[0] is undefined" JS error appears in "misc/tabledrag.js" file |
||
203 | * Then check that "TypeError: cell[0] is undefined" JS error appears on the page |
||
204 | * |
||
205 | * @Then /^check that "([^"]*)" JS error(| not) appears (?:in "([^"]*)" file|on the page)$/ |
||
206 | * |
||
207 | * @javascript |
||
208 | */ |
||
209 | public function checkJavaScriptError($message, $negate, $file = '') |
||
210 | { |
||
211 | $errors = $this->getSession()->evaluateScript('return JSON.stringify(window.errors);'); |
||
212 | $negate = (bool) $negate; |
||
213 | |||
214 | if (empty($errors)) { |
||
215 | if (!$negate) { |
||
216 | throw new \RuntimeException('Page does not contain JavaScript errors.'); |
||
217 | } |
||
218 | } else { |
||
219 | $base_url = $this->locatePath(); |
||
220 | |||
221 | // The "$error" object contains two properties: "message" and "location". |
||
222 | // @see CatchErrors.js |
||
223 | foreach (json_decode($errors) as $error) { |
||
224 | $error->location = str_replace($base_url, '', $error->location); |
||
225 | |||
226 | self::debug(['JS error "%s" in "%s" file'], [$error->message, $error->location]); |
||
227 | |||
228 | switch (static::assertion( |
||
229 | strpos($error->message, $message) === 0 && ('' === $file ?: strpos($error->location, $file) === 0), |
||
230 | $negate |
||
231 | )) { |
||
232 | case 1: |
||
233 | throw new \Exception(sprintf('The "%s" error found, but should not be.', $message)); |
||
234 | |||
235 | case 2: |
||
236 | throw new \Exception(sprintf('The "%s" error not found, but should be.', $message)); |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @param string $selector |
||
244 | * @param string $attribute |
||
245 | * @param string $expectedValue |
||
246 | * |
||
247 | * @throws \Exception |
||
248 | * |
||
249 | * @example |
||
250 | * Then I should see the "#table_cell" element with "colspan" attribute having "3" value |
||
251 | * |
||
252 | * @Then /^(?:|I )should see the "([^"]*)" element with "([^"]*)" attribute having "([^"]*)" value$/ |
||
253 | */ |
||
254 | public function assertElementAttribute($selector, $attribute, $expectedValue) |
||
268 | |||
269 | /** |
||
270 | * @param Scope\BeforeFeatureScope $scope |
||
271 | * Scope of the processing feature. |
||
272 | * |
||
273 | * @BeforeFeature |
||
274 | */ |
||
275 | public static function beforeFeature(Scope\BeforeFeatureScope $scope) |
||
287 | |||
288 | /** |
||
289 | * @AfterFeature |
||
290 | */ |
||
291 | public static function afterFeature() |
||
299 | |||
300 | /** |
||
301 | * @param Scope\BeforeScenarioScope $scope |
||
302 | * Scope of the processing scenario. |
||
303 | * |
||
304 | * @BeforeScenario |
||
305 | */ |
||
306 | public function beforeScenario(Scope\BeforeScenarioScope $scope) |
||
316 | |||
317 | /** |
||
318 | * Track XMLHttpRequest starts and finishes using pure JavaScript. |
||
319 | * |
||
320 | * @see RawTqContext::waitAjaxAndAnimations() |
||
321 | * |
||
322 | * @BeforeScenario @javascript |
||
323 | */ |
||
324 | public function beforeScenarioJS() |
||
328 | |||
329 | /** |
||
330 | * IMPORTANT! The "BeforeStep" hook should not be tagged, because steps has no tags! |
||
331 | * |
||
332 | * @param Scope\StepScope|Scope\BeforeStepScope $scope |
||
333 | * Scope of the processing step. |
||
334 | * |
||
335 | * @BeforeStep |
||
336 | */ |
||
337 | public function beforeStep(Scope\StepScope $scope) |
||
343 | |||
344 | /** |
||
345 | * IMPORTANT! The "AfterStep" hook should not be tagged, because steps has no tags! |
||
346 | * |
||
347 | * @param Scope\StepScope|Scope\AfterStepScope $scope |
||
348 | * Scope of the processing step. |
||
349 | * |
||
350 | * @AfterStep |
||
351 | */ |
||
352 | public function afterStep(Scope\StepScope $scope) |
||
366 | } |
||
367 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: