commit | author | age
|
2207d6
|
1 |
# AngularJS |
W |
2 |
|
|
3 |
|
|
4 |
Module for AngularJS testing, based on [WebDriver module](http://codeception.com/docs/modules/WebDriver) and [Protractor](http://angular.github.io/protractor/). |
|
5 |
|
|
6 |
Performs **synchronization to ensure that page content is fully rendered**. |
|
7 |
Uses Angular's and Protractor internals methods to synchronize with the page. |
|
8 |
|
|
9 |
## Configuration |
|
10 |
|
|
11 |
The same as for [WebDriver](http://codeception.com/docs/modules/WebDriver#Configuration), but few new options added: |
|
12 |
|
|
13 |
* `el` - element where Angular application is defined (default: `body`) |
|
14 |
* `script_timeout` - for how long in seconds to wait for angular operations to finish (default: 5) |
|
15 |
|
|
16 |
### Example (`acceptance.suite.yml`) |
|
17 |
|
|
18 |
modules: |
|
19 |
enabled: |
|
20 |
- AngularJS: |
|
21 |
url: 'http://localhost/' |
|
22 |
browser: firefox |
|
23 |
script_timeout: 10 |
|
24 |
|
|
25 |
|
|
26 |
### Additional Features |
|
27 |
|
|
28 |
Can perform matching elements by model. In this case you should provide a strict locator with `model` set. |
|
29 |
|
|
30 |
Example: |
|
31 |
|
|
32 |
```php |
|
33 |
$I->selectOption(['model' => 'customerId'], '3'); |
|
34 |
``` |
|
35 |
|
|
36 |
## Actions |
|
37 |
|
|
38 |
### _backupSession |
|
39 |
|
|
40 |
*hidden API method, expected to be used from Helper classes* |
|
41 |
|
|
42 |
Returns current WebDriver session for saving |
|
43 |
|
|
44 |
* `return` RemoteWebDriver |
|
45 |
|
|
46 |
|
|
47 |
### _capabilities |
|
48 |
|
|
49 |
*hidden API method, expected to be used from Helper classes* |
|
50 |
|
|
51 |
Change capabilities of WebDriver. Should be executed before starting a new browser session. |
|
52 |
This method expects a function to be passed which returns array or [WebDriver Desired Capabilities](https://github.com/facebook/php-webdriver/blob/community/lib/Remote/DesiredCapabilities.php) object. |
|
53 |
Additional [Chrome options](https://github.com/facebook/php-webdriver/wiki/ChromeOptions) (like adding extensions) can be passed as well. |
|
54 |
|
|
55 |
```php |
|
56 |
<?php // in helper |
|
57 |
public function _before(TestInterface $test) |
|
58 |
{ |
|
59 |
$this->getModule('WebDriver')->_capabilities(function($currentCapabilities) { |
|
60 |
// or new \Facebook\WebDriver\Remote\DesiredCapabilities(); |
|
61 |
return \Facebook\WebDriver\Remote\DesiredCapabilities::firefox(); |
|
62 |
}); |
|
63 |
} |
|
64 |
``` |
|
65 |
|
|
66 |
to make this work load `\Helper\Acceptance` before `WebDriver` in `acceptance.suite.yml`: |
|
67 |
|
|
68 |
```yaml |
|
69 |
modules: |
|
70 |
enabled: |
|
71 |
- \Helper\Acceptance |
|
72 |
- WebDriver |
|
73 |
``` |
|
74 |
|
|
75 |
For instance, [**BrowserStack** cloud service](https://www.browserstack.com/automate/capabilities) may require a test name to be set in capabilities. |
|
76 |
This is how it can be done via `_capabilities` method from `Helper\Acceptance`: |
|
77 |
|
|
78 |
```php |
|
79 |
<?php // inside Helper\Acceptance |
|
80 |
public function _before(TestInterface $test) |
|
81 |
{ |
|
82 |
$name = $test->getMetadata()->getName(); |
|
83 |
$this->getModule('WebDriver')->_capabilities(function($currentCapabilities) use ($name) { |
|
84 |
$currentCapabilities['name'] = $name; |
|
85 |
return $currentCapabilities; |
|
86 |
}); |
|
87 |
} |
|
88 |
``` |
|
89 |
In this case, please ensure that `\Helper\Acceptance` is loaded before WebDriver so new capabilities could be applied. |
|
90 |
|
|
91 |
* `param \Closure` $capabilityFunction |
|
92 |
|
|
93 |
|
|
94 |
### _closeSession |
|
95 |
|
|
96 |
*hidden API method, expected to be used from Helper classes* |
|
97 |
|
|
98 |
Manually closes current WebDriver session. |
|
99 |
|
|
100 |
```php |
|
101 |
<?php |
|
102 |
$this->getModule('WebDriver')->_closeSession(); |
|
103 |
|
|
104 |
// close a specific session |
|
105 |
$webDriver = $this->getModule('WebDriver')->webDriver; |
|
106 |
$this->getModule('WebDriver')->_closeSession($webDriver); |
|
107 |
``` |
|
108 |
|
|
109 |
* `param` $webDriver (optional) a specific webdriver session instance |
|
110 |
|
|
111 |
|
|
112 |
### _findClickable |
|
113 |
|
|
114 |
*hidden API method, expected to be used from Helper classes* |
|
115 |
|
|
116 |
Locates a clickable element. |
|
117 |
|
|
118 |
Use it in Helpers or GroupObject or Extension classes: |
|
119 |
|
|
120 |
```php |
|
121 |
<?php |
|
122 |
$module = $this->getModule('WebDriver'); |
|
123 |
$page = $module->webDriver; |
|
124 |
|
|
125 |
// search a link or button on a page |
|
126 |
$el = $module->_findClickable($page, 'Click Me'); |
|
127 |
|
|
128 |
// search a link or button within an element |
|
129 |
$topBar = $module->_findElements('.top-bar')[0]; |
|
130 |
$el = $module->_findClickable($topBar, 'Click Me'); |
|
131 |
|
|
132 |
``` |
|
133 |
* `param RemoteWebDriver` $page WebDriver instance or an element to search within |
|
134 |
* `param` $link a link text or locator to click |
|
135 |
* `return` WebDriverElement |
|
136 |
|
|
137 |
|
|
138 |
### _findElements |
|
139 |
|
|
140 |
*hidden API method, expected to be used from Helper classes* |
|
141 |
|
|
142 |
Locates element using available Codeception locator types: |
|
143 |
|
|
144 |
* XPath |
|
145 |
* CSS |
|
146 |
* Strict Locator |
|
147 |
|
|
148 |
Use it in Helpers or GroupObject or Extension classes: |
|
149 |
|
|
150 |
```php |
|
151 |
<?php |
|
152 |
$els = $this->getModule('AngularJS')->_findElements('.items'); |
|
153 |
$els = $this->getModule('AngularJS')->_findElements(['name' => 'username']); |
|
154 |
|
|
155 |
$editLinks = $this->getModule('AngularJS')->_findElements(['link' => 'Edit']); |
|
156 |
// now you can iterate over $editLinks and check that all them have valid hrefs |
|
157 |
``` |
|
158 |
|
|
159 |
WebDriver module returns `Facebook\WebDriver\Remote\RemoteWebElement` instances |
|
160 |
PhpBrowser and Framework modules return `Symfony\Component\DomCrawler\Crawler` instances |
|
161 |
|
|
162 |
* `param` $locator |
|
163 |
* `return` array of interactive elements |
|
164 |
|
|
165 |
|
|
166 |
### _getCurrentUri |
|
167 |
|
|
168 |
*hidden API method, expected to be used from Helper classes* |
|
169 |
|
|
170 |
Uri of currently opened page. |
|
171 |
* `return` string |
|
172 |
@throws ModuleException |
|
173 |
|
|
174 |
|
|
175 |
### _getUrl |
|
176 |
|
|
177 |
*hidden API method, expected to be used from Helper classes* |
|
178 |
|
|
179 |
Returns URL of a host. |
|
180 |
|
|
181 |
@throws ModuleConfigException |
|
182 |
|
|
183 |
|
|
184 |
### _initializeSession |
|
185 |
|
|
186 |
*hidden API method, expected to be used from Helper classes* |
|
187 |
|
|
188 |
Manually starts a new browser session. |
|
189 |
|
|
190 |
```php |
|
191 |
<?php |
|
192 |
$this->getModule('WebDriver')->_initializeSession(); |
|
193 |
``` |
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
### _loadSession |
|
198 |
|
|
199 |
*hidden API method, expected to be used from Helper classes* |
|
200 |
|
|
201 |
Loads current RemoteWebDriver instance as a session |
|
202 |
|
|
203 |
* `param RemoteWebDriver` $session |
|
204 |
|
|
205 |
|
|
206 |
### _restart |
|
207 |
|
|
208 |
*hidden API method, expected to be used from Helper classes* |
|
209 |
|
|
210 |
Restarts a web browser. |
|
211 |
Can be used with `_reconfigure` to open browser with different configuration |
|
212 |
|
|
213 |
```php |
|
214 |
<?php |
|
215 |
// inside a Helper |
|
216 |
$this->getModule('WebDriver')->_restart(); // just restart |
|
217 |
$this->getModule('WebDriver')->_restart(['browser' => $browser]); // reconfigure + restart |
|
218 |
``` |
|
219 |
|
|
220 |
* `param array` $config |
|
221 |
|
|
222 |
|
|
223 |
### _savePageSource |
|
224 |
|
|
225 |
*hidden API method, expected to be used from Helper classes* |
|
226 |
|
|
227 |
Saves HTML source of a page to a file |
|
228 |
* `param` $filename |
|
229 |
|
|
230 |
|
|
231 |
### _saveScreenshot |
|
232 |
|
|
233 |
*hidden API method, expected to be used from Helper classes* |
|
234 |
|
|
235 |
Saves screenshot of current page to a file |
|
236 |
|
|
237 |
```php |
|
238 |
$this->getModule('AngularJS')->_saveScreenshot(codecept_output_dir().'screenshot_1.png'); |
|
239 |
``` |
|
240 |
* `param` $filename |
|
241 |
|
|
242 |
|
|
243 |
### acceptPopup |
|
244 |
|
|
245 |
Accepts the active JavaScript native popup window, as created by `window.alert`|`window.confirm`|`window.prompt`. |
|
246 |
Don't confuse popups with modal windows, |
|
247 |
as created by [various libraries](http://jster.net/category/windows-modals-popups). |
|
248 |
|
|
249 |
|
|
250 |
### amInsideAngularApp |
|
251 |
|
|
252 |
Enables Angular mode (enabled by default). |
|
253 |
Waits for Angular to finish rendering after each action. |
|
254 |
|
|
255 |
|
|
256 |
### amOnPage |
|
257 |
|
|
258 |
Opens the page for the given relative URI. |
|
259 |
|
|
260 |
``` php |
|
261 |
<?php |
|
262 |
// opens front page |
|
263 |
$I->amOnPage('/'); |
|
264 |
// opens /register page |
|
265 |
$I->amOnPage('/register'); |
|
266 |
``` |
|
267 |
|
|
268 |
* `param string` $page |
|
269 |
|
|
270 |
|
|
271 |
### amOnSubdomain |
|
272 |
|
|
273 |
Changes the subdomain for the 'url' configuration parameter. |
|
274 |
Does not open a page; use `amOnPage` for that. |
|
275 |
|
|
276 |
``` php |
|
277 |
<?php |
|
278 |
// If config is: 'http://mysite.com' |
|
279 |
// or config is: 'http://www.mysite.com' |
|
280 |
// or config is: 'http://company.mysite.com' |
|
281 |
|
|
282 |
$I->amOnSubdomain('user'); |
|
283 |
$I->amOnPage('/'); |
|
284 |
// moves to http://user.mysite.com/ |
|
285 |
?> |
|
286 |
``` |
|
287 |
|
|
288 |
* `param` $subdomain |
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
### amOnUrl |
|
293 |
|
|
294 |
Open web page at the given absolute URL and sets its hostname as the base host. |
|
295 |
|
|
296 |
``` php |
|
297 |
<?php |
|
298 |
$I->amOnUrl('http://codeception.com'); |
|
299 |
$I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart |
|
300 |
?> |
|
301 |
``` |
|
302 |
|
|
303 |
|
|
304 |
### amOutsideAngularApp |
|
305 |
|
|
306 |
Disabled Angular mode. |
|
307 |
|
|
308 |
Falls back to original WebDriver, in case web page does not contain Angular app. |
|
309 |
|
|
310 |
|
|
311 |
### appendField |
|
312 |
|
|
313 |
Append the given text to the given element. |
|
314 |
Can also add a selection to a select box. |
|
315 |
|
|
316 |
``` php |
|
317 |
<?php |
|
318 |
$I->appendField('#mySelectbox', 'SelectValue'); |
|
319 |
$I->appendField('#myTextField', 'appended'); |
|
320 |
?> |
|
321 |
``` |
|
322 |
|
|
323 |
* `param string` $field |
|
324 |
* `param string` $value |
|
325 |
@throws \Codeception\Exception\ElementNotFound |
|
326 |
|
|
327 |
|
|
328 |
### attachFile |
|
329 |
|
|
330 |
Attaches a file relative to the Codeception `_data` directory to the given file upload field. |
|
331 |
|
|
332 |
``` php |
|
333 |
<?php |
|
334 |
// file is stored in 'tests/_data/prices.xls' |
|
335 |
$I->attachFile('input[@type="file"]', 'prices.xls'); |
|
336 |
?> |
|
337 |
``` |
|
338 |
|
|
339 |
* `param` $field |
|
340 |
* `param` $filename |
|
341 |
|
|
342 |
|
|
343 |
### cancelPopup |
|
344 |
|
|
345 |
Dismisses the active JavaScript popup, as created by `window.alert`, `window.confirm`, or `window.prompt`. |
|
346 |
|
|
347 |
|
|
348 |
### checkOption |
|
349 |
|
|
350 |
Ticks a checkbox. For radio buttons, use the `selectOption` method instead. |
|
351 |
|
|
352 |
``` php |
|
353 |
<?php |
|
354 |
$I->checkOption('#agree'); |
|
355 |
?> |
|
356 |
``` |
|
357 |
|
|
358 |
* `param` $option |
|
359 |
|
|
360 |
|
|
361 |
### clearField |
|
362 |
|
|
363 |
Clears given field which isn't empty. |
|
364 |
|
|
365 |
``` php |
|
366 |
<?php |
|
367 |
$I->clearField('#username'); |
|
368 |
``` |
|
369 |
|
|
370 |
* `param` $field |
|
371 |
|
|
372 |
|
|
373 |
### click |
|
374 |
|
|
375 |
Perform a click on a link or a button, given by a locator. |
|
376 |
If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. |
|
377 |
For buttons, the "value" attribute, "name" attribute, and inner text are searched. |
|
378 |
For links, the link text is searched. |
|
379 |
For images, the "alt" attribute and inner text of any parent links are searched. |
|
380 |
|
|
381 |
The second parameter is a context (CSS or XPath locator) to narrow the search. |
|
382 |
|
|
383 |
Note that if the locator matches a button of type `submit`, the form will be submitted. |
|
384 |
|
|
385 |
``` php |
|
386 |
<?php |
|
387 |
// simple link |
|
388 |
$I->click('Logout'); |
|
389 |
// button of form |
|
390 |
$I->click('Submit'); |
|
391 |
// CSS button |
|
392 |
$I->click('#form input[type=submit]'); |
|
393 |
// XPath |
|
394 |
$I->click('//form/*[@type=submit]'); |
|
395 |
// link in context |
|
396 |
$I->click('Logout', '#nav'); |
|
397 |
// using strict locator |
|
398 |
$I->click(['link' => 'Login']); |
|
399 |
?> |
|
400 |
``` |
|
401 |
|
|
402 |
* `param` $link |
|
403 |
* `param` $context |
|
404 |
|
|
405 |
|
|
406 |
### clickWithLeftButton |
|
407 |
|
|
408 |
Performs click with the left mouse button on an element. |
|
409 |
If the first parameter `null` then the offset is relative to the actual mouse position. |
|
410 |
If the second and third parameters are given, |
|
411 |
then the mouse is moved to an offset of the element's top-left corner. |
|
412 |
Otherwise, the mouse is moved to the center of the element. |
|
413 |
|
|
414 |
``` php |
|
415 |
<?php |
|
416 |
$I->clickWithLeftButton(['css' => '.checkout']); |
|
417 |
$I->clickWithLeftButton(null, 20, 50); |
|
418 |
$I->clickWithLeftButton(['css' => '.checkout'], 20, 50); |
|
419 |
?> |
|
420 |
``` |
|
421 |
|
|
422 |
* `param string` $cssOrXPath css or xpath of the web element (body by default). |
|
423 |
* `param int` $offsetX |
|
424 |
* `param int` $offsetY |
|
425 |
|
|
426 |
@throws \Codeception\Exception\ElementNotFound |
|
427 |
|
|
428 |
|
|
429 |
### clickWithRightButton |
|
430 |
|
|
431 |
Performs contextual click with the right mouse button on an element. |
|
432 |
If the first parameter `null` then the offset is relative to the actual mouse position. |
|
433 |
If the second and third parameters are given, |
|
434 |
then the mouse is moved to an offset of the element's top-left corner. |
|
435 |
Otherwise, the mouse is moved to the center of the element. |
|
436 |
|
|
437 |
``` php |
|
438 |
<?php |
|
439 |
$I->clickWithRightButton(['css' => '.checkout']); |
|
440 |
$I->clickWithRightButton(null, 20, 50); |
|
441 |
$I->clickWithRightButton(['css' => '.checkout'], 20, 50); |
|
442 |
?> |
|
443 |
``` |
|
444 |
|
|
445 |
* `param string` $cssOrXPath css or xpath of the web element (body by default). |
|
446 |
* `param int` $offsetX |
|
447 |
* `param int` $offsetY |
|
448 |
|
|
449 |
@throws \Codeception\Exception\ElementNotFound |
|
450 |
|
|
451 |
|
|
452 |
### closeTab |
|
453 |
|
|
454 |
Closes current browser tab and switches to previous active tab. |
|
455 |
|
|
456 |
```php |
|
457 |
<?php |
|
458 |
$I->closeTab(); |
|
459 |
``` |
|
460 |
|
|
461 |
Can't be used with PhantomJS |
|
462 |
|
|
463 |
|
|
464 |
### debugWebDriverLogs |
|
465 |
|
|
466 |
Print out latest Selenium Logs in debug mode |
|
467 |
|
|
468 |
* `param \Codeception\TestInterface` $test |
|
469 |
|
|
470 |
|
|
471 |
### deleteSessionSnapshot |
|
472 |
|
|
473 |
Deletes session snapshot. |
|
474 |
|
|
475 |
See [saveSessionSnapshot](#saveSessionSnapshot) |
|
476 |
|
|
477 |
* `param` $name |
|
478 |
|
|
479 |
|
|
480 |
### dontSee |
|
481 |
|
|
482 |
Checks that the current page doesn't contain the text specified (case insensitive). |
|
483 |
Give a locator as the second parameter to match a specific region. |
|
484 |
|
|
485 |
```php |
|
486 |
<?php |
|
487 |
$I->dontSee('Login'); // I can suppose user is already logged in |
|
488 |
$I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page |
|
489 |
$I->dontSee('Sign Up','//body/h1'); // with XPath |
|
490 |
$I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator |
|
491 |
``` |
|
492 |
|
|
493 |
Note that the search is done after stripping all HTML tags from the body, |
|
494 |
so `$I->dontSee('strong')` will fail on strings like: |
|
495 |
|
|
496 |
- `<p>I am Stronger than thou</p>` |
|
497 |
- `<script>document.createElement('strong');</script>` |
|
498 |
|
|
499 |
But will ignore strings like: |
|
500 |
|
|
501 |
- `<strong>Home</strong>` |
|
502 |
- `<div class="strong">Home</strong>` |
|
503 |
- `<!-- strong -->` |
|
504 |
|
|
505 |
For checking the raw source code, use `seeInSource()`. |
|
506 |
|
|
507 |
* `param string` $text |
|
508 |
* `param string` $selector optional |
|
509 |
|
|
510 |
|
|
511 |
### dontSeeCheckboxIsChecked |
|
512 |
|
|
513 |
Check that the specified checkbox is unchecked. |
|
514 |
|
|
515 |
``` php |
|
516 |
<?php |
|
517 |
$I->dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms |
|
518 |
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. |
|
519 |
?> |
|
520 |
``` |
|
521 |
|
|
522 |
* `param` $checkbox |
|
523 |
|
|
524 |
|
|
525 |
### dontSeeCookie |
|
526 |
|
|
527 |
Checks that there isn't a cookie with the given name. |
|
528 |
You can set additional cookie params like `domain`, `path` as array passed in last argument. |
|
529 |
|
|
530 |
* `param` $cookie |
|
531 |
|
|
532 |
* `param array` $params |
|
533 |
|
|
534 |
|
|
535 |
### dontSeeCurrentUrlEquals |
|
536 |
|
|
537 |
Checks that the current URL doesn't equal the given string. |
|
538 |
Unlike `dontSeeInCurrentUrl`, this only matches the full URL. |
|
539 |
|
|
540 |
``` php |
|
541 |
<?php |
|
542 |
// current url is not root |
|
543 |
$I->dontSeeCurrentUrlEquals('/'); |
|
544 |
?> |
|
545 |
``` |
|
546 |
|
|
547 |
* `param string` $uri |
|
548 |
|
|
549 |
|
|
550 |
### dontSeeCurrentUrlMatches |
|
551 |
|
|
552 |
Checks that current url doesn't match the given regular expression. |
|
553 |
|
|
554 |
``` php |
|
555 |
<?php |
|
556 |
// to match root url |
|
557 |
$I->dontSeeCurrentUrlMatches('~^/users/(\d+)~'); |
|
558 |
?> |
|
559 |
``` |
|
560 |
|
|
561 |
* `param string` $uri |
|
562 |
|
|
563 |
|
|
564 |
### dontSeeElement |
|
565 |
|
|
566 |
Checks that the given element is invisible or not present on the page. |
|
567 |
You can also specify expected attributes of this element. |
|
568 |
|
|
569 |
``` php |
|
570 |
<?php |
|
571 |
$I->dontSeeElement('.error'); |
|
572 |
$I->dontSeeElement('//form/input[1]'); |
|
573 |
$I->dontSeeElement('input', ['name' => 'login']); |
|
574 |
$I->dontSeeElement('input', ['value' => '123456']); |
|
575 |
?> |
|
576 |
``` |
|
577 |
|
|
578 |
* `param` $selector |
|
579 |
* `param array` $attributes |
|
580 |
|
|
581 |
|
|
582 |
### dontSeeElementInDOM |
|
583 |
|
|
584 |
Opposite of `seeElementInDOM`. |
|
585 |
|
|
586 |
* `param` $selector |
|
587 |
* `param array` $attributes |
|
588 |
|
|
589 |
|
|
590 |
### dontSeeInCurrentUrl |
|
591 |
|
|
592 |
Checks that the current URI doesn't contain the given string. |
|
593 |
|
|
594 |
``` php |
|
595 |
<?php |
|
596 |
$I->dontSeeInCurrentUrl('/users/'); |
|
597 |
?> |
|
598 |
``` |
|
599 |
|
|
600 |
* `param string` $uri |
|
601 |
|
|
602 |
|
|
603 |
### dontSeeInField |
|
604 |
|
|
605 |
Checks that an input field or textarea doesn't contain the given value. |
|
606 |
For fuzzy locators, the field is matched by label text, CSS and XPath. |
|
607 |
|
|
608 |
``` php |
|
609 |
<?php |
|
610 |
$I->dontSeeInField('Body','Type your comment here'); |
|
611 |
$I->dontSeeInField('form textarea[name=body]','Type your comment here'); |
|
612 |
$I->dontSeeInField('form input[type=hidden]','hidden_value'); |
|
613 |
$I->dontSeeInField('#searchform input','Search'); |
|
614 |
$I->dontSeeInField('//form/*[@name=search]','Search'); |
|
615 |
$I->dontSeeInField(['name' => 'search'], 'Search'); |
|
616 |
?> |
|
617 |
``` |
|
618 |
|
|
619 |
* `param` $field |
|
620 |
* `param` $value |
|
621 |
|
|
622 |
|
|
623 |
### dontSeeInFormFields |
|
624 |
|
|
625 |
Checks if the array of form parameters (name => value) are not set on the form matched with |
|
626 |
the passed selector. |
|
627 |
|
|
628 |
``` php |
|
629 |
<?php |
|
630 |
$I->dontSeeInFormFields('form[name=myform]', [ |
|
631 |
'input1' => 'non-existent value', |
|
632 |
'input2' => 'other non-existent value', |
|
633 |
]); |
|
634 |
?> |
|
635 |
``` |
|
636 |
|
|
637 |
To check that an element hasn't been assigned any one of many values, an array can be passed |
|
638 |
as the value: |
|
639 |
|
|
640 |
``` php |
|
641 |
<?php |
|
642 |
$I->dontSeeInFormFields('.form-class', [ |
|
643 |
'fieldName' => [ |
|
644 |
'This value shouldn\'t be set', |
|
645 |
'And this value shouldn\'t be set', |
|
646 |
], |
|
647 |
]); |
|
648 |
?> |
|
649 |
``` |
|
650 |
|
|
651 |
Additionally, checkbox values can be checked with a boolean. |
|
652 |
|
|
653 |
``` php |
|
654 |
<?php |
|
655 |
$I->dontSeeInFormFields('#form-id', [ |
|
656 |
'checkbox1' => true, // fails if checked |
|
657 |
'checkbox2' => false, // fails if unchecked |
|
658 |
]); |
|
659 |
?> |
|
660 |
``` |
|
661 |
|
|
662 |
* `param` $formSelector |
|
663 |
* `param` $params |
|
664 |
|
|
665 |
|
|
666 |
### dontSeeInPageSource |
|
667 |
|
|
668 |
Checks that the page source doesn't contain the given string. |
|
669 |
|
|
670 |
* `param` $text |
|
671 |
|
|
672 |
|
|
673 |
### dontSeeInPopup |
|
674 |
|
|
675 |
Checks that the active JavaScript popup, |
|
676 |
as created by `window.alert`|`window.confirm`|`window.prompt`, does NOT contain the given string. |
|
677 |
|
|
678 |
* `param` $text |
|
679 |
|
|
680 |
@throws \Codeception\Exception\ModuleException |
|
681 |
|
|
682 |
|
|
683 |
### dontSeeInSource |
|
684 |
|
|
685 |
Checks that the current page contains the given string in its |
|
686 |
raw source code. |
|
687 |
|
|
688 |
```php |
|
689 |
<?php |
|
690 |
$I->dontSeeInSource('<h1>Green eggs & ham</h1>'); |
|
691 |
``` |
|
692 |
|
|
693 |
* `param` $raw |
|
694 |
|
|
695 |
|
|
696 |
### dontSeeInTitle |
|
697 |
|
|
698 |
Checks that the page title does not contain the given string. |
|
699 |
|
|
700 |
* `param` $title |
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
### dontSeeLink |
|
705 |
|
|
706 |
Checks that the page doesn't contain a link with the given string. |
|
707 |
If the second parameter is given, only links with a matching "href" attribute will be checked. |
|
708 |
|
|
709 |
``` php |
|
710 |
<?php |
|
711 |
$I->dontSeeLink('Logout'); // I suppose user is not logged in |
|
712 |
$I->dontSeeLink('Checkout now', '/store/cart.php'); |
|
713 |
?> |
|
714 |
``` |
|
715 |
|
|
716 |
* `param string` $text |
|
717 |
* `param string` $url optional |
|
718 |
|
|
719 |
|
|
720 |
### dontSeeOptionIsSelected |
|
721 |
|
|
722 |
Checks that the given option is not selected. |
|
723 |
|
|
724 |
``` php |
|
725 |
<?php |
|
726 |
$I->dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); |
|
727 |
?> |
|
728 |
``` |
|
729 |
|
|
730 |
* `param` $selector |
|
731 |
* `param` $optionText |
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
### doubleClick |
|
736 |
|
|
737 |
Performs a double-click on an element matched by CSS or XPath. |
|
738 |
|
|
739 |
* `param` $cssOrXPath |
|
740 |
@throws \Codeception\Exception\ElementNotFound |
|
741 |
|
|
742 |
|
|
743 |
### dragAndDrop |
|
744 |
|
|
745 |
Performs a simple mouse drag-and-drop operation. |
|
746 |
|
|
747 |
``` php |
|
748 |
<?php |
|
749 |
$I->dragAndDrop('#drag', '#drop'); |
|
750 |
?> |
|
751 |
``` |
|
752 |
|
|
753 |
* `param string` $source (CSS ID or XPath) |
|
754 |
* `param string` $target (CSS ID or XPath) |
|
755 |
|
|
756 |
|
|
757 |
### executeAsyncJS |
|
758 |
|
|
759 |
Executes asynchronous JavaScript. |
|
760 |
A callback should be executed by JavaScript to exit from a script. |
|
761 |
Callback is passed as a last element in `arguments` array. |
|
762 |
Additional arguments can be passed as array in second parameter. |
|
763 |
|
|
764 |
```js |
|
765 |
// wait for 1200 milliseconds my running `setTimeout` |
|
766 |
* $I->executeAsyncJS('setTimeout(arguments[0], 1200)'); |
|
767 |
|
|
768 |
$seconds = 1200; // or seconds are passed as argument |
|
769 |
$I->executeAsyncJS('setTimeout(arguments[1], arguments[0])', [$seconds]); |
|
770 |
``` |
|
771 |
|
|
772 |
* `param` $script |
|
773 |
* `param array` $arguments |
|
774 |
|
|
775 |
|
|
776 |
### executeInSelenium |
|
777 |
|
|
778 |
Low-level API method. |
|
779 |
If Codeception commands are not enough, this allows you to use Selenium WebDriver methods directly: |
|
780 |
|
|
781 |
``` php |
|
782 |
$I->executeInSelenium(function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { |
|
783 |
$webdriver->get('http://google.com'); |
|
784 |
}); |
|
785 |
``` |
|
786 |
|
|
787 |
This runs in the context of the |
|
788 |
[RemoteWebDriver class](https://github.com/facebook/php-webdriver/blob/master/lib/remote/RemoteWebDriver.php). |
|
789 |
Try not to use this command on a regular basis. |
|
790 |
If Codeception lacks a feature you need, please implement it and submit a patch. |
|
791 |
|
|
792 |
* `param callable` $function |
|
793 |
|
|
794 |
|
|
795 |
### executeJS |
|
796 |
|
|
797 |
Executes custom JavaScript. |
|
798 |
|
|
799 |
This example uses jQuery to get a value and assigns that value to a PHP variable: |
|
800 |
|
|
801 |
```php |
|
802 |
<?php |
|
803 |
$myVar = $I->executeJS('return $("#myField").val()'); |
|
804 |
|
|
805 |
// additional arguments can be passed as array |
|
806 |
// Example shows `Hello World` alert: |
|
807 |
$I->executeJS("window.alert(arguments[0])", ['Hello world']); |
|
808 |
``` |
|
809 |
|
|
810 |
* `param` $script |
|
811 |
* `param array` $arguments |
|
812 |
|
|
813 |
|
|
814 |
### fillField |
|
815 |
|
|
816 |
Fills a text field or textarea with the given string. |
|
817 |
|
|
818 |
``` php |
|
819 |
<?php |
|
820 |
$I->fillField("//input[@type='text']", "Hello World!"); |
|
821 |
$I->fillField(['name' => 'email'], 'jon@mail.com'); |
|
822 |
?> |
|
823 |
``` |
|
824 |
|
|
825 |
* `param` $field |
|
826 |
* `param` $value |
|
827 |
|
|
828 |
|
|
829 |
### grabAttributeFrom |
|
830 |
|
|
831 |
Grabs the value of the given attribute value from the given element. |
|
832 |
Fails if element is not found. |
|
833 |
|
|
834 |
``` php |
|
835 |
<?php |
|
836 |
$I->grabAttributeFrom('#tooltip', 'title'); |
|
837 |
?> |
|
838 |
``` |
|
839 |
|
|
840 |
* `param` $cssOrXpath |
|
841 |
* `param` $attribute |
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
### grabCookie |
|
846 |
|
|
847 |
Grabs a cookie value. |
|
848 |
You can set additional cookie params like `domain`, `path` in array passed as last argument. |
|
849 |
|
|
850 |
* `param` $cookie |
|
851 |
|
|
852 |
* `param array` $params |
|
853 |
|
|
854 |
|
|
855 |
### grabFromCurrentUrl |
|
856 |
|
|
857 |
Executes the given regular expression against the current URI and returns the first capturing group. |
|
858 |
If no parameters are provided, the full URI is returned. |
|
859 |
|
|
860 |
``` php |
|
861 |
<?php |
|
862 |
$user_id = $I->grabFromCurrentUrl('~^/user/(\d+)/~'); |
|
863 |
$uri = $I->grabFromCurrentUrl(); |
|
864 |
?> |
|
865 |
``` |
|
866 |
|
|
867 |
* `param string` $uri optional |
|
868 |
|
|
869 |
|
|
870 |
|
|
871 |
### grabMultiple |
|
872 |
|
|
873 |
Grabs either the text content, or attribute values, of nodes |
|
874 |
matched by $cssOrXpath and returns them as an array. |
|
875 |
|
|
876 |
```html |
|
877 |
<a href="#first">First</a> |
|
878 |
<a href="#second">Second</a> |
|
879 |
<a href="#third">Third</a> |
|
880 |
``` |
|
881 |
|
|
882 |
```php |
|
883 |
<?php |
|
884 |
// would return ['First', 'Second', 'Third'] |
|
885 |
$aLinkText = $I->grabMultiple('a'); |
|
886 |
|
|
887 |
// would return ['#first', '#second', '#third'] |
|
888 |
$aLinks = $I->grabMultiple('a', 'href'); |
|
889 |
?> |
|
890 |
``` |
|
891 |
|
|
892 |
* `param` $cssOrXpath |
|
893 |
* `param` $attribute |
|
894 |
* `return` string[] |
|
895 |
|
|
896 |
|
|
897 |
### grabPageSource |
|
898 |
|
|
899 |
Grabs current page source code. |
|
900 |
|
|
901 |
@throws ModuleException if no page was opened. |
|
902 |
|
|
903 |
* `return` string Current page source code. |
|
904 |
|
|
905 |
|
|
906 |
### grabTextFrom |
|
907 |
|
|
908 |
Finds and returns the text contents of the given element. |
|
909 |
If a fuzzy locator is used, the element is found using CSS, XPath, |
|
910 |
and by matching the full page source by regular expression. |
|
911 |
|
|
912 |
``` php |
|
913 |
<?php |
|
914 |
$heading = $I->grabTextFrom('h1'); |
|
915 |
$heading = $I->grabTextFrom('descendant-or-self::h1'); |
|
916 |
$value = $I->grabTextFrom('~<input value=(.*?)]~sgi'); // match with a regex |
|
917 |
?> |
|
918 |
``` |
|
919 |
|
|
920 |
* `param` $cssOrXPathOrRegex |
|
921 |
|
|
922 |
|
|
923 |
|
|
924 |
### grabValueFrom |
|
925 |
|
|
926 |
Finds the value for the given form field. |
|
927 |
If a fuzzy locator is used, the field is found by field name, CSS, and XPath. |
|
928 |
|
|
929 |
``` php |
|
930 |
<?php |
|
931 |
$name = $I->grabValueFrom('Name'); |
|
932 |
$name = $I->grabValueFrom('input[name=username]'); |
|
933 |
$name = $I->grabValueFrom('descendant-or-self::form/descendant::input[@name = 'username']'); |
|
934 |
$name = $I->grabValueFrom(['name' => 'username']); |
|
935 |
?> |
|
936 |
``` |
|
937 |
|
|
938 |
* `param` $field |
|
939 |
|
|
940 |
|
|
941 |
|
|
942 |
### loadSessionSnapshot |
|
943 |
|
|
944 |
Loads cookies from a saved snapshot. |
|
945 |
Allows to reuse same session across tests without additional login. |
|
946 |
|
|
947 |
See [saveSessionSnapshot](#saveSessionSnapshot) |
|
948 |
|
|
949 |
* `param` $name |
|
950 |
|
|
951 |
|
|
952 |
### makeScreenshot |
|
953 |
|
|
954 |
Takes a screenshot of the current window and saves it to `tests/_output/debug`. |
|
955 |
|
|
956 |
``` php |
|
957 |
<?php |
|
958 |
$I->amOnPage('/user/edit'); |
|
959 |
$I->makeScreenshot('edit_page'); |
|
960 |
// saved to: tests/_output/debug/edit_page.png |
|
961 |
$I->makeScreenshot(); |
|
962 |
// saved to: tests/_output/debug/2017-05-26_14-24-11_4b3403665fea6.png |
|
963 |
``` |
|
964 |
|
|
965 |
* `param` $name |
|
966 |
|
|
967 |
|
|
968 |
### maximizeWindow |
|
969 |
|
|
970 |
Maximizes the current window. |
|
971 |
|
|
972 |
|
|
973 |
### moveBack |
|
974 |
|
|
975 |
Moves back in history. |
|
976 |
|
|
977 |
|
|
978 |
### moveForward |
|
979 |
|
|
980 |
Moves forward in history. |
|
981 |
|
|
982 |
|
|
983 |
### moveMouseOver |
|
984 |
|
|
985 |
Move mouse over the first element matched by the given locator. |
|
986 |
If the first parameter null then the page is used. |
|
987 |
If the second and third parameters are given, |
|
988 |
then the mouse is moved to an offset of the element's top-left corner. |
|
989 |
Otherwise, the mouse is moved to the center of the element. |
|
990 |
|
|
991 |
``` php |
|
992 |
<?php |
|
993 |
$I->moveMouseOver(['css' => '.checkout']); |
|
994 |
$I->moveMouseOver(null, 20, 50); |
|
995 |
$I->moveMouseOver(['css' => '.checkout'], 20, 50); |
|
996 |
?> |
|
997 |
``` |
|
998 |
|
|
999 |
* `param string` $cssOrXPath css or xpath of the web element |
|
1000 |
* `param int` $offsetX |
|
1001 |
* `param int` $offsetY |
|
1002 |
|
|
1003 |
@throws \Codeception\Exception\ElementNotFound |
|
1004 |
|
|
1005 |
|
|
1006 |
### openNewTab |
|
1007 |
|
|
1008 |
Opens a new browser tab (wherever it is possible) and switches to it. |
|
1009 |
|
|
1010 |
```php |
|
1011 |
<?php |
|
1012 |
$I->openNewTab(); |
|
1013 |
``` |
|
1014 |
Tab is opened by using `window.open` javascript in a browser. |
|
1015 |
Please note, that adblock can restrict creating such tabs. |
|
1016 |
|
|
1017 |
Can't be used with PhantomJS |
|
1018 |
|
|
1019 |
|
|
1020 |
|
|
1021 |
### pauseExecution |
|
1022 |
|
|
1023 |
Pauses test execution in debug mode. |
|
1024 |
To proceed test press "ENTER" in console. |
|
1025 |
|
|
1026 |
This method is useful while writing tests, |
|
1027 |
since it allows you to inspect the current page in the middle of a test case. |
|
1028 |
|
|
1029 |
|
|
1030 |
### performOn |
|
1031 |
|
|
1032 |
Waits for element and runs a sequence of actions inside its context. |
|
1033 |
Actions can be defined with array, callback, or `Codeception\Util\ActionSequence` instance. |
|
1034 |
|
|
1035 |
Actions as array are recommended for simple to combine "waitForElement" with assertions; |
|
1036 |
`waitForElement($el)` and `see('text', $el)` can be simplified to: |
|
1037 |
|
|
1038 |
```php |
|
1039 |
<?php |
|
1040 |
$I->performOn($el, ['see' => 'text']); |
|
1041 |
``` |
|
1042 |
|
|
1043 |
List of actions can be pragmatically build using `Codeception\Util\ActionSequence`: |
|
1044 |
|
|
1045 |
```php |
|
1046 |
<?php |
|
1047 |
$I->performOn('.model', ActionSequence::build() |
|
1048 |
->see('Warning') |
|
1049 |
->see('Are you sure you want to delete this?') |
|
1050 |
->click('Yes') |
|
1051 |
); |
|
1052 |
``` |
|
1053 |
|
|
1054 |
Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to |
|
1055 |
exception on failure. |
|
1056 |
|
|
1057 |
Whenever you need to define more actions a callback can be used. A WebDriver module is passed for argument: |
|
1058 |
|
|
1059 |
```php |
|
1060 |
<?php |
|
1061 |
$I->performOn('.rememberMe', function (WebDriver $I) { |
|
1062 |
$I->see('Remember me next time'); |
|
1063 |
$I->seeElement('#LoginForm_rememberMe'); |
|
1064 |
$I->dontSee('Login'); |
|
1065 |
}); |
|
1066 |
``` |
|
1067 |
|
|
1068 |
In 3rd argument you can set number a seconds to wait for element to appear |
|
1069 |
|
|
1070 |
* `param` $element |
|
1071 |
* `param` $actions |
|
1072 |
* `param int` $timeout |
|
1073 |
|
|
1074 |
|
|
1075 |
### pressKey |
|
1076 |
|
|
1077 |
Presses the given key on the given element. |
|
1078 |
To specify a character and modifier (e.g. ctrl, alt, shift, meta), pass an array for $char with |
|
1079 |
the modifier as the first element and the character as the second. |
|
1080 |
For special keys use key constants from WebDriverKeys class. |
|
1081 |
|
|
1082 |
``` php |
|
1083 |
<?php |
|
1084 |
// <input id="page" value="old" /> |
|
1085 |
$I->pressKey('#page','a'); // => olda |
|
1086 |
$I->pressKey('#page',array('ctrl','a'),'new'); //=> new |
|
1087 |
$I->pressKey('#page',array('shift','111'),'1','x'); //=> old!!!1x |
|
1088 |
$I->pressKey('descendant-or-self::*[@id='page']','u'); //=> oldu |
|
1089 |
$I->pressKey('#name', array('ctrl', 'a'), \Facebook\WebDriver\WebDriverKeys::DELETE); //=>'' |
|
1090 |
?> |
|
1091 |
``` |
|
1092 |
|
|
1093 |
* `param` $element |
|
1094 |
* `param` $char string|array Can be char or array with modifier. You can provide several chars. |
|
1095 |
@throws \Codeception\Exception\ElementNotFound |
|
1096 |
|
|
1097 |
|
|
1098 |
### reloadPage |
|
1099 |
|
|
1100 |
Reloads the current page. |
|
1101 |
|
|
1102 |
|
|
1103 |
### resetCookie |
|
1104 |
|
|
1105 |
Unsets cookie with the given name. |
|
1106 |
You can set additional cookie params like `domain`, `path` in array passed as last argument. |
|
1107 |
|
|
1108 |
* `param` $cookie |
|
1109 |
|
|
1110 |
* `param array` $params |
|
1111 |
|
|
1112 |
|
|
1113 |
### resizeWindow |
|
1114 |
|
|
1115 |
Resize the current window. |
|
1116 |
|
|
1117 |
``` php |
|
1118 |
<?php |
|
1119 |
$I->resizeWindow(800, 600); |
|
1120 |
|
|
1121 |
``` |
|
1122 |
|
|
1123 |
* `param int` $width |
|
1124 |
* `param int` $height |
|
1125 |
|
|
1126 |
|
|
1127 |
### saveSessionSnapshot |
|
1128 |
|
|
1129 |
Saves current cookies into named snapshot in order to restore them in other tests |
|
1130 |
This is useful to save session state between tests. |
|
1131 |
For example, if user needs log in to site for each test this scenario can be executed once |
|
1132 |
while other tests can just restore saved cookies. |
|
1133 |
|
|
1134 |
``` php |
|
1135 |
<?php |
|
1136 |
// inside AcceptanceTester class: |
|
1137 |
|
|
1138 |
public function login() |
|
1139 |
{ |
|
1140 |
// if snapshot exists - skipping login |
|
1141 |
if ($I->loadSessionSnapshot('login')) return; |
|
1142 |
|
|
1143 |
// logging in |
|
1144 |
$I->amOnPage('/login'); |
|
1145 |
$I->fillField('name', 'jon'); |
|
1146 |
$I->fillField('password', '123345'); |
|
1147 |
$I->click('Login'); |
|
1148 |
|
|
1149 |
// saving snapshot |
|
1150 |
$I->saveSessionSnapshot('login'); |
|
1151 |
} |
|
1152 |
?> |
|
1153 |
``` |
|
1154 |
|
|
1155 |
* `param` $name |
|
1156 |
|
|
1157 |
|
|
1158 |
### scrollTo |
|
1159 |
|
|
1160 |
Move to the middle of the given element matched by the given locator. |
|
1161 |
Extra shift, calculated from the top-left corner of the element, |
|
1162 |
can be set by passing $offsetX and $offsetY parameters. |
|
1163 |
|
|
1164 |
``` php |
|
1165 |
<?php |
|
1166 |
$I->scrollTo(['css' => '.checkout'], 20, 50); |
|
1167 |
?> |
|
1168 |
``` |
|
1169 |
|
|
1170 |
* `param` $selector |
|
1171 |
* `param int` $offsetX |
|
1172 |
* `param int` $offsetY |
|
1173 |
|
|
1174 |
|
|
1175 |
### see |
|
1176 |
|
|
1177 |
Checks that the current page contains the given string (case insensitive). |
|
1178 |
|
|
1179 |
You can specify a specific HTML element (via CSS or XPath) as the second |
|
1180 |
parameter to only search within that element. |
|
1181 |
|
|
1182 |
``` php |
|
1183 |
<?php |
|
1184 |
$I->see('Logout'); // I can suppose user is logged in |
|
1185 |
$I->see('Sign Up', 'h1'); // I can suppose it's a signup page |
|
1186 |
$I->see('Sign Up', '//body/h1'); // with XPath |
|
1187 |
$I->see('Sign Up', ['css' => 'body h1']); // with strict CSS locator |
|
1188 |
``` |
|
1189 |
|
|
1190 |
Note that the search is done after stripping all HTML tags from the body, |
|
1191 |
so `$I->see('strong')` will return true for strings like: |
|
1192 |
|
|
1193 |
- `<p>I am Stronger than thou</p>` |
|
1194 |
- `<script>document.createElement('strong');</script>` |
|
1195 |
|
|
1196 |
But will *not* be true for strings like: |
|
1197 |
|
|
1198 |
- `<strong>Home</strong>` |
|
1199 |
- `<div class="strong">Home</strong>` |
|
1200 |
- `<!-- strong -->` |
|
1201 |
|
|
1202 |
For checking the raw source code, use `seeInSource()`. |
|
1203 |
|
|
1204 |
* `param string` $text |
|
1205 |
* `param string` $selector optional |
|
1206 |
|
|
1207 |
|
|
1208 |
### seeCheckboxIsChecked |
|
1209 |
|
|
1210 |
Checks that the specified checkbox is checked. |
|
1211 |
|
|
1212 |
``` php |
|
1213 |
<?php |
|
1214 |
$I->seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms |
|
1215 |
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. |
|
1216 |
$I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); |
|
1217 |
?> |
|
1218 |
``` |
|
1219 |
|
|
1220 |
* `param` $checkbox |
|
1221 |
|
|
1222 |
|
|
1223 |
### seeCookie |
|
1224 |
|
|
1225 |
Checks that a cookie with the given name is set. |
|
1226 |
You can set additional cookie params like `domain`, `path` as array passed in last argument. |
|
1227 |
|
|
1228 |
``` php |
|
1229 |
<?php |
|
1230 |
$I->seeCookie('PHPSESSID'); |
|
1231 |
?> |
|
1232 |
``` |
|
1233 |
|
|
1234 |
* `param` $cookie |
|
1235 |
* `param array` $params |
|
1236 |
|
|
1237 |
|
|
1238 |
### seeCurrentUrlEquals |
|
1239 |
|
|
1240 |
Checks that the current URL is equal to the given string. |
|
1241 |
Unlike `seeInCurrentUrl`, this only matches the full URL. |
|
1242 |
|
|
1243 |
``` php |
|
1244 |
<?php |
|
1245 |
// to match root url |
|
1246 |
$I->seeCurrentUrlEquals('/'); |
|
1247 |
?> |
|
1248 |
``` |
|
1249 |
|
|
1250 |
* `param string` $uri |
|
1251 |
|
|
1252 |
|
|
1253 |
### seeCurrentUrlMatches |
|
1254 |
|
|
1255 |
Checks that the current URL matches the given regular expression. |
|
1256 |
|
|
1257 |
``` php |
|
1258 |
<?php |
|
1259 |
// to match root url |
|
1260 |
$I->seeCurrentUrlMatches('~^/users/(\d+)~'); |
|
1261 |
?> |
|
1262 |
``` |
|
1263 |
|
|
1264 |
* `param string` $uri |
|
1265 |
|
|
1266 |
|
|
1267 |
### seeElement |
|
1268 |
|
|
1269 |
Checks that the given element exists on the page and is visible. |
|
1270 |
You can also specify expected attributes of this element. |
|
1271 |
|
|
1272 |
``` php |
|
1273 |
<?php |
|
1274 |
$I->seeElement('.error'); |
|
1275 |
$I->seeElement('//form/input[1]'); |
|
1276 |
$I->seeElement('input', ['name' => 'login']); |
|
1277 |
$I->seeElement('input', ['value' => '123456']); |
|
1278 |
|
|
1279 |
// strict locator in first arg, attributes in second |
|
1280 |
$I->seeElement(['css' => 'form input'], ['name' => 'login']); |
|
1281 |
?> |
|
1282 |
``` |
|
1283 |
|
|
1284 |
* `param` $selector |
|
1285 |
* `param array` $attributes |
|
1286 |
@return |
|
1287 |
|
|
1288 |
|
|
1289 |
### seeElementInDOM |
|
1290 |
|
|
1291 |
Checks that the given element exists on the page, even it is invisible. |
|
1292 |
|
|
1293 |
``` php |
|
1294 |
<?php |
|
1295 |
$I->seeElementInDOM('//form/input[type=hidden]'); |
|
1296 |
?> |
|
1297 |
``` |
|
1298 |
|
|
1299 |
* `param` $selector |
|
1300 |
* `param array` $attributes |
|
1301 |
|
|
1302 |
|
|
1303 |
### seeInCurrentUrl |
|
1304 |
|
|
1305 |
Checks that current URI contains the given string. |
|
1306 |
|
|
1307 |
``` php |
|
1308 |
<?php |
|
1309 |
// to match: /home/dashboard |
|
1310 |
$I->seeInCurrentUrl('home'); |
|
1311 |
// to match: /users/1 |
|
1312 |
$I->seeInCurrentUrl('/users/'); |
|
1313 |
?> |
|
1314 |
``` |
|
1315 |
|
|
1316 |
* `param string` $uri |
|
1317 |
|
|
1318 |
|
|
1319 |
### seeInField |
|
1320 |
|
|
1321 |
Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. |
|
1322 |
Fields are matched by label text, the "name" attribute, CSS, or XPath. |
|
1323 |
|
|
1324 |
``` php |
|
1325 |
<?php |
|
1326 |
$I->seeInField('Body','Type your comment here'); |
|
1327 |
$I->seeInField('form textarea[name=body]','Type your comment here'); |
|
1328 |
$I->seeInField('form input[type=hidden]','hidden_value'); |
|
1329 |
$I->seeInField('#searchform input','Search'); |
|
1330 |
$I->seeInField('//form/*[@name=search]','Search'); |
|
1331 |
$I->seeInField(['name' => 'search'], 'Search'); |
|
1332 |
?> |
|
1333 |
``` |
|
1334 |
|
|
1335 |
* `param` $field |
|
1336 |
* `param` $value |
|
1337 |
|
|
1338 |
|
|
1339 |
### seeInFormFields |
|
1340 |
|
|
1341 |
Checks if the array of form parameters (name => value) are set on the form matched with the |
|
1342 |
passed selector. |
|
1343 |
|
|
1344 |
``` php |
|
1345 |
<?php |
|
1346 |
$I->seeInFormFields('form[name=myform]', [ |
|
1347 |
'input1' => 'value', |
|
1348 |
'input2' => 'other value', |
|
1349 |
]); |
|
1350 |
?> |
|
1351 |
``` |
|
1352 |
|
|
1353 |
For multi-select elements, or to check values of multiple elements with the same name, an |
|
1354 |
array may be passed: |
|
1355 |
|
|
1356 |
``` php |
|
1357 |
<?php |
|
1358 |
$I->seeInFormFields('.form-class', [ |
|
1359 |
'multiselect' => [ |
|
1360 |
'value1', |
|
1361 |
'value2', |
|
1362 |
], |
|
1363 |
'checkbox[]' => [ |
|
1364 |
'a checked value', |
|
1365 |
'another checked value', |
|
1366 |
], |
|
1367 |
]); |
|
1368 |
?> |
|
1369 |
``` |
|
1370 |
|
|
1371 |
Additionally, checkbox values can be checked with a boolean. |
|
1372 |
|
|
1373 |
``` php |
|
1374 |
<?php |
|
1375 |
$I->seeInFormFields('#form-id', [ |
|
1376 |
'checkbox1' => true, // passes if checked |
|
1377 |
'checkbox2' => false, // passes if unchecked |
|
1378 |
]); |
|
1379 |
?> |
|
1380 |
``` |
|
1381 |
|
|
1382 |
Pair this with submitForm for quick testing magic. |
|
1383 |
|
|
1384 |
``` php |
|
1385 |
<?php |
|
1386 |
$form = [ |
|
1387 |
'field1' => 'value', |
|
1388 |
'field2' => 'another value', |
|
1389 |
'checkbox1' => true, |
|
1390 |
// ... |
|
1391 |
]; |
|
1392 |
$I->submitForm('//form[@id=my-form]', $form, 'submitButton'); |
|
1393 |
// $I->amOnPage('/path/to/form-page') may be needed |
|
1394 |
$I->seeInFormFields('//form[@id=my-form]', $form); |
|
1395 |
?> |
|
1396 |
``` |
|
1397 |
|
|
1398 |
* `param` $formSelector |
|
1399 |
* `param` $params |
|
1400 |
|
|
1401 |
|
|
1402 |
### seeInPageSource |
|
1403 |
|
|
1404 |
Checks that the page source contains the given string. |
|
1405 |
|
|
1406 |
```php |
|
1407 |
<?php |
|
1408 |
$I->seeInPageSource('<link rel="apple-touch-icon"'); |
|
1409 |
``` |
|
1410 |
|
|
1411 |
* `param` $text |
|
1412 |
|
|
1413 |
|
|
1414 |
### seeInPopup |
|
1415 |
|
|
1416 |
Checks that the active JavaScript popup, |
|
1417 |
as created by `window.alert`|`window.confirm`|`window.prompt`, contains the given string. |
|
1418 |
|
|
1419 |
* `param` $text |
|
1420 |
|
|
1421 |
@throws \Codeception\Exception\ModuleException |
|
1422 |
|
|
1423 |
|
|
1424 |
### seeInSource |
|
1425 |
|
|
1426 |
Checks that the current page contains the given string in its |
|
1427 |
raw source code. |
|
1428 |
|
|
1429 |
``` php |
|
1430 |
<?php |
|
1431 |
$I->seeInSource('<h1>Green eggs & ham</h1>'); |
|
1432 |
``` |
|
1433 |
|
|
1434 |
* `param` $raw |
|
1435 |
|
|
1436 |
|
|
1437 |
### seeInTitle |
|
1438 |
|
|
1439 |
Checks that the page title contains the given string. |
|
1440 |
|
|
1441 |
``` php |
|
1442 |
<?php |
|
1443 |
$I->seeInTitle('Blog - Post #1'); |
|
1444 |
?> |
|
1445 |
``` |
|
1446 |
|
|
1447 |
* `param` $title |
|
1448 |
|
|
1449 |
|
|
1450 |
|
|
1451 |
### seeLink |
|
1452 |
|
|
1453 |
Checks that there's a link with the specified text. |
|
1454 |
Give a full URL as the second parameter to match links with that exact URL. |
|
1455 |
|
|
1456 |
``` php |
|
1457 |
<?php |
|
1458 |
$I->seeLink('Logout'); // matches <a href="#">Logout</a> |
|
1459 |
$I->seeLink('Logout','/logout'); // matches <a href="/logout">Logout</a> |
|
1460 |
?> |
|
1461 |
``` |
|
1462 |
|
|
1463 |
* `param string` $text |
|
1464 |
* `param string` $url optional |
|
1465 |
|
|
1466 |
|
|
1467 |
### seeNumberOfElements |
|
1468 |
|
|
1469 |
Checks that there are a certain number of elements matched by the given locator on the page. |
|
1470 |
|
|
1471 |
``` php |
|
1472 |
<?php |
|
1473 |
$I->seeNumberOfElements('tr', 10); |
|
1474 |
$I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements |
|
1475 |
?> |
|
1476 |
``` |
|
1477 |
* `param` $selector |
|
1478 |
* `param mixed` $expected int or int[] |
|
1479 |
|
|
1480 |
|
|
1481 |
### seeNumberOfElementsInDOM |
|
1482 |
__not documented__ |
|
1483 |
|
|
1484 |
|
|
1485 |
### seeOptionIsSelected |
|
1486 |
|
|
1487 |
Checks that the given option is selected. |
|
1488 |
|
|
1489 |
``` php |
|
1490 |
<?php |
|
1491 |
$I->seeOptionIsSelected('#form input[name=payment]', 'Visa'); |
|
1492 |
?> |
|
1493 |
``` |
|
1494 |
|
|
1495 |
* `param` $selector |
|
1496 |
* `param` $optionText |
|
1497 |
|
|
1498 |
|
|
1499 |
|
|
1500 |
### selectOption |
|
1501 |
|
|
1502 |
Selects an option in a select tag or in radio button group. |
|
1503 |
|
|
1504 |
``` php |
|
1505 |
<?php |
|
1506 |
$I->selectOption('form select[name=account]', 'Premium'); |
|
1507 |
$I->selectOption('form input[name=payment]', 'Monthly'); |
|
1508 |
$I->selectOption('//form/select[@name=account]', 'Monthly'); |
|
1509 |
?> |
|
1510 |
``` |
|
1511 |
|
|
1512 |
Provide an array for the second argument to select multiple options: |
|
1513 |
|
|
1514 |
``` php |
|
1515 |
<?php |
|
1516 |
$I->selectOption('Which OS do you use?', array('Windows','Linux')); |
|
1517 |
?> |
|
1518 |
``` |
|
1519 |
|
|
1520 |
Or provide an associative array for the second argument to specifically define which selection method should be used: |
|
1521 |
|
|
1522 |
``` php |
|
1523 |
<?php |
|
1524 |
$I->selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' |
|
1525 |
$I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' |
|
1526 |
?> |
|
1527 |
``` |
|
1528 |
|
|
1529 |
* `param` $select |
|
1530 |
* `param` $option |
|
1531 |
|
|
1532 |
|
|
1533 |
### setCookie |
|
1534 |
|
|
1535 |
Sets a cookie with the given name and value. |
|
1536 |
You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. |
|
1537 |
|
|
1538 |
``` php |
|
1539 |
<?php |
|
1540 |
$I->setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); |
|
1541 |
?> |
|
1542 |
``` |
|
1543 |
|
|
1544 |
* `param` $name |
|
1545 |
* `param` $val |
|
1546 |
* `param array` $params |
|
1547 |
|
|
1548 |
|
|
1549 |
|
|
1550 |
### submitForm |
|
1551 |
|
|
1552 |
Submits the given form on the page, optionally with the given form |
|
1553 |
values. Give the form fields values as an array. Note that hidden fields |
|
1554 |
can't be accessed. |
|
1555 |
|
|
1556 |
Skipped fields will be filled by their values from the page. |
|
1557 |
You don't need to click the 'Submit' button afterwards. |
|
1558 |
This command itself triggers the request to form's action. |
|
1559 |
|
|
1560 |
You can optionally specify what button's value to include |
|
1561 |
in the request with the last parameter as an alternative to |
|
1562 |
explicitly setting its value in the second parameter, as |
|
1563 |
button values are not otherwise included in the request. |
|
1564 |
|
|
1565 |
Examples: |
|
1566 |
|
|
1567 |
``` php |
|
1568 |
<?php |
|
1569 |
$I->submitForm('#login', [ |
|
1570 |
'login' => 'davert', |
|
1571 |
'password' => '123456' |
|
1572 |
]); |
|
1573 |
// or |
|
1574 |
$I->submitForm('#login', [ |
|
1575 |
'login' => 'davert', |
|
1576 |
'password' => '123456' |
|
1577 |
], 'submitButtonName'); |
|
1578 |
|
|
1579 |
``` |
|
1580 |
|
|
1581 |
For example, given this sample "Sign Up" form: |
|
1582 |
|
|
1583 |
``` html |
|
1584 |
<form action="/sign_up"> |
|
1585 |
Login: |
|
1586 |
<input type="text" name="user[login]" /><br/> |
|
1587 |
Password: |
|
1588 |
<input type="password" name="user[password]" /><br/> |
|
1589 |
Do you agree to our terms? |
|
1590 |
<input type="checkbox" name="user[agree]" /><br/> |
|
1591 |
Select pricing plan: |
|
1592 |
<select name="plan"> |
|
1593 |
<option value="1">Free</option> |
|
1594 |
<option value="2" selected="selected">Paid</option> |
|
1595 |
</select> |
|
1596 |
<input type="submit" name="submitButton" value="Submit" /> |
|
1597 |
</form> |
|
1598 |
``` |
|
1599 |
|
|
1600 |
You could write the following to submit it: |
|
1601 |
|
|
1602 |
``` php |
|
1603 |
<?php |
|
1604 |
$I->submitForm( |
|
1605 |
'#userForm', |
|
1606 |
[ |
|
1607 |
'user[login]' => 'Davert', |
|
1608 |
'user[password]' => '123456', |
|
1609 |
'user[agree]' => true |
|
1610 |
], |
|
1611 |
'submitButton' |
|
1612 |
); |
|
1613 |
``` |
|
1614 |
Note that "2" will be the submitted value for the "plan" field, as it is |
|
1615 |
the selected option. |
|
1616 |
|
|
1617 |
Also note that this differs from PhpBrowser, in that |
|
1618 |
```'user' => [ 'login' => 'Davert' ]``` is not supported at the moment. |
|
1619 |
Named array keys *must* be included in the name as above. |
|
1620 |
|
|
1621 |
Pair this with seeInFormFields for quick testing magic. |
|
1622 |
|
|
1623 |
``` php |
|
1624 |
<?php |
|
1625 |
$form = [ |
|
1626 |
'field1' => 'value', |
|
1627 |
'field2' => 'another value', |
|
1628 |
'checkbox1' => true, |
|
1629 |
// ... |
|
1630 |
]; |
|
1631 |
$I->submitForm('//form[@id=my-form]', $form, 'submitButton'); |
|
1632 |
// $I->amOnPage('/path/to/form-page') may be needed |
|
1633 |
$I->seeInFormFields('//form[@id=my-form]', $form); |
|
1634 |
?> |
|
1635 |
``` |
|
1636 |
|
|
1637 |
Parameter values must be set to arrays for multiple input fields |
|
1638 |
of the same name, or multi-select combo boxes. For checkboxes, |
|
1639 |
either the string value can be used, or boolean values which will |
|
1640 |
be replaced by the checkbox's value in the DOM. |
|
1641 |
|
|
1642 |
``` php |
|
1643 |
<?php |
|
1644 |
$I->submitForm('#my-form', [ |
|
1645 |
'field1' => 'value', |
|
1646 |
'checkbox' => [ |
|
1647 |
'value of first checkbox', |
|
1648 |
'value of second checkbox, |
|
1649 |
], |
|
1650 |
'otherCheckboxes' => [ |
|
1651 |
true, |
|
1652 |
false, |
|
1653 |
false |
|
1654 |
], |
|
1655 |
'multiselect' => [ |
|
1656 |
'first option value', |
|
1657 |
'second option value' |
|
1658 |
] |
|
1659 |
]); |
|
1660 |
?> |
|
1661 |
``` |
|
1662 |
|
|
1663 |
Mixing string and boolean values for a checkbox's value is not supported |
|
1664 |
and may produce unexpected results. |
|
1665 |
|
|
1666 |
Field names ending in "[]" must be passed without the trailing square |
|
1667 |
bracket characters, and must contain an array for its value. This allows |
|
1668 |
submitting multiple values with the same name, consider: |
|
1669 |
|
|
1670 |
```php |
|
1671 |
$I->submitForm('#my-form', [ |
|
1672 |
'field[]' => 'value', |
|
1673 |
'field[]' => 'another value', // 'field[]' is already a defined key |
|
1674 |
]); |
|
1675 |
``` |
|
1676 |
|
|
1677 |
The solution is to pass an array value: |
|
1678 |
|
|
1679 |
```php |
|
1680 |
// this way both values are submitted |
|
1681 |
$I->submitForm('#my-form', [ |
|
1682 |
'field' => [ |
|
1683 |
'value', |
|
1684 |
'another value', |
|
1685 |
] |
|
1686 |
]); |
|
1687 |
``` |
|
1688 |
|
|
1689 |
The `$button` parameter can be either a string, an array or an instance |
|
1690 |
of Facebook\WebDriver\WebDriverBy. When it is a string, the |
|
1691 |
button will be found by its "name" attribute. If $button is an |
|
1692 |
array then it will be treated as a strict selector and a WebDriverBy |
|
1693 |
will be used verbatim. |
|
1694 |
|
|
1695 |
For example, given the following HTML: |
|
1696 |
|
|
1697 |
``` html |
|
1698 |
<input type="submit" name="submitButton" value="Submit" /> |
|
1699 |
``` |
|
1700 |
|
|
1701 |
`$button` could be any one of the following: |
|
1702 |
- 'submitButton' |
|
1703 |
- ['name' => 'submitButton'] |
|
1704 |
- WebDriverBy::name('submitButton') |
|
1705 |
|
|
1706 |
* `param` $selector |
|
1707 |
* `param` $params |
|
1708 |
* `param` $button |
|
1709 |
|
|
1710 |
|
|
1711 |
### switchToIFrame |
|
1712 |
|
|
1713 |
Switch to another frame on the page. |
|
1714 |
|
|
1715 |
Example: |
|
1716 |
``` html |
|
1717 |
<iframe name="another_frame" src="http://example.com"> |
|
1718 |
|
|
1719 |
``` |
|
1720 |
|
|
1721 |
``` php |
|
1722 |
<?php |
|
1723 |
# switch to iframe |
|
1724 |
$I->switchToIFrame("another_frame"); |
|
1725 |
# switch to parent page |
|
1726 |
$I->switchToIFrame(); |
|
1727 |
|
|
1728 |
``` |
|
1729 |
|
|
1730 |
* `param string|null` $name |
|
1731 |
|
|
1732 |
|
|
1733 |
### switchToNextTab |
|
1734 |
|
|
1735 |
Switches to next browser tab. |
|
1736 |
An offset can be specified. |
|
1737 |
|
|
1738 |
```php |
|
1739 |
<?php |
|
1740 |
// switch to next tab |
|
1741 |
$I->switchToNextTab(); |
|
1742 |
// switch to 2nd next tab |
|
1743 |
$I->switchToNextTab(2); |
|
1744 |
``` |
|
1745 |
|
|
1746 |
Can't be used with PhantomJS |
|
1747 |
|
|
1748 |
* `param int` $offset 1 |
|
1749 |
|
|
1750 |
|
|
1751 |
### switchToPreviousTab |
|
1752 |
|
|
1753 |
Switches to previous browser tab. |
|
1754 |
An offset can be specified. |
|
1755 |
|
|
1756 |
```php |
|
1757 |
<?php |
|
1758 |
// switch to previous tab |
|
1759 |
$I->switchToPreviousTab(); |
|
1760 |
// switch to 2nd previous tab |
|
1761 |
$I->switchToPreviousTab(2); |
|
1762 |
``` |
|
1763 |
|
|
1764 |
Can't be used with PhantomJS |
|
1765 |
|
|
1766 |
* `param int` $offset 1 |
|
1767 |
|
|
1768 |
|
|
1769 |
### switchToWindow |
|
1770 |
|
|
1771 |
Switch to another window identified by name. |
|
1772 |
|
|
1773 |
The window can only be identified by name. If the $name parameter is blank, the parent window will be used. |
|
1774 |
|
|
1775 |
Example: |
|
1776 |
``` html |
|
1777 |
<input type="button" value="Open window" onclick="window.open('http://example.com', 'another_window')"> |
|
1778 |
``` |
|
1779 |
|
|
1780 |
``` php |
|
1781 |
<?php |
|
1782 |
$I->click("Open window"); |
|
1783 |
# switch to another window |
|
1784 |
$I->switchToWindow("another_window"); |
|
1785 |
# switch to parent window |
|
1786 |
$I->switchToWindow(); |
|
1787 |
?> |
|
1788 |
``` |
|
1789 |
|
|
1790 |
If the window has no name, match it by switching to next active tab using `switchToNextTab` method. |
|
1791 |
|
|
1792 |
Or use native Selenium functions to get access to all opened windows: |
|
1793 |
|
|
1794 |
``` php |
|
1795 |
<?php |
|
1796 |
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { |
|
1797 |
$handles=$webdriver->getWindowHandles(); |
|
1798 |
$last_window = end($handles); |
|
1799 |
$webdriver->switchTo()->window($last_window); |
|
1800 |
}); |
|
1801 |
?> |
|
1802 |
``` |
|
1803 |
|
|
1804 |
* `param string|null` $name |
|
1805 |
|
|
1806 |
|
|
1807 |
### typeInPopup |
|
1808 |
|
|
1809 |
Enters text into a native JavaScript prompt popup, as created by `window.prompt`. |
|
1810 |
|
|
1811 |
* `param` $keys |
|
1812 |
|
|
1813 |
@throws \Codeception\Exception\ModuleException |
|
1814 |
|
|
1815 |
|
|
1816 |
### uncheckOption |
|
1817 |
|
|
1818 |
Unticks a checkbox. |
|
1819 |
|
|
1820 |
``` php |
|
1821 |
<?php |
|
1822 |
$I->uncheckOption('#notify'); |
|
1823 |
?> |
|
1824 |
``` |
|
1825 |
|
|
1826 |
* `param` $option |
|
1827 |
|
|
1828 |
|
|
1829 |
### unselectOption |
|
1830 |
|
|
1831 |
Unselect an option in the given select box. |
|
1832 |
|
|
1833 |
* `param` $select |
|
1834 |
* `param` $option |
|
1835 |
|
|
1836 |
|
|
1837 |
### wait |
|
1838 |
|
|
1839 |
Wait for $timeout seconds. |
|
1840 |
|
|
1841 |
* `param int|float` $timeout secs |
|
1842 |
@throws \Codeception\Exception\TestRuntimeException |
|
1843 |
|
|
1844 |
|
|
1845 |
### waitForElement |
|
1846 |
|
|
1847 |
Waits up to $timeout seconds for an element to appear on the page. |
|
1848 |
If the element doesn't appear, a timeout exception is thrown. |
|
1849 |
|
|
1850 |
``` php |
|
1851 |
<?php |
|
1852 |
$I->waitForElement('#agree_button', 30); // secs |
|
1853 |
$I->click('#agree_button'); |
|
1854 |
?> |
|
1855 |
``` |
|
1856 |
|
|
1857 |
* `param` $element |
|
1858 |
* `param int` $timeout seconds |
|
1859 |
@throws \Exception |
|
1860 |
|
|
1861 |
|
|
1862 |
### waitForElementChange |
|
1863 |
|
|
1864 |
Waits up to $timeout seconds for the given element to change. |
|
1865 |
Element "change" is determined by a callback function which is called repeatedly |
|
1866 |
until the return value evaluates to true. |
|
1867 |
|
|
1868 |
``` php |
|
1869 |
<?php |
|
1870 |
use \Facebook\WebDriver\WebDriverElement |
|
1871 |
$I->waitForElementChange('#menu', function(WebDriverElement $el) { |
|
1872 |
return $el->isDisplayed(); |
|
1873 |
}, 100); |
|
1874 |
?> |
|
1875 |
``` |
|
1876 |
|
|
1877 |
* `param` $element |
|
1878 |
* `param \Closure` $callback |
|
1879 |
* `param int` $timeout seconds |
|
1880 |
@throws \Codeception\Exception\ElementNotFound |
|
1881 |
|
|
1882 |
|
|
1883 |
### waitForElementClickable |
|
1884 |
|
|
1885 |
Waits up to $timeout seconds for the given element to be clickable. |
|
1886 |
If element doesn't become clickable, a timeout exception is thrown. |
|
1887 |
|
|
1888 |
``` php |
|
1889 |
<?php |
|
1890 |
$I->waitForElementClickable('#agree_button', 30); // secs |
|
1891 |
$I->click('#agree_button'); |
|
1892 |
?> |
|
1893 |
``` |
|
1894 |
|
|
1895 |
* `param` $element |
|
1896 |
* `param int` $timeout seconds |
|
1897 |
@throws \Exception |
|
1898 |
|
|
1899 |
|
|
1900 |
### waitForElementNotVisible |
|
1901 |
|
|
1902 |
Waits up to $timeout seconds for the given element to become invisible. |
|
1903 |
If element stays visible, a timeout exception is thrown. |
|
1904 |
|
|
1905 |
``` php |
|
1906 |
<?php |
|
1907 |
$I->waitForElementNotVisible('#agree_button', 30); // secs |
|
1908 |
?> |
|
1909 |
``` |
|
1910 |
|
|
1911 |
* `param` $element |
|
1912 |
* `param int` $timeout seconds |
|
1913 |
@throws \Exception |
|
1914 |
|
|
1915 |
|
|
1916 |
### waitForElementVisible |
|
1917 |
|
|
1918 |
Waits up to $timeout seconds for the given element to be visible on the page. |
|
1919 |
If element doesn't appear, a timeout exception is thrown. |
|
1920 |
|
|
1921 |
``` php |
|
1922 |
<?php |
|
1923 |
$I->waitForElementVisible('#agree_button', 30); // secs |
|
1924 |
$I->click('#agree_button'); |
|
1925 |
?> |
|
1926 |
``` |
|
1927 |
|
|
1928 |
* `param` $element |
|
1929 |
* `param int` $timeout seconds |
|
1930 |
@throws \Exception |
|
1931 |
|
|
1932 |
|
|
1933 |
### waitForJS |
|
1934 |
|
|
1935 |
Executes JavaScript and waits up to $timeout seconds for it to return true. |
|
1936 |
|
|
1937 |
In this example we will wait up to 60 seconds for all jQuery AJAX requests to finish. |
|
1938 |
|
|
1939 |
``` php |
|
1940 |
<?php |
|
1941 |
$I->waitForJS("return $.active == 0;", 60); |
|
1942 |
?> |
|
1943 |
``` |
|
1944 |
|
|
1945 |
* `param string` $script |
|
1946 |
* `param int` $timeout seconds |
|
1947 |
|
|
1948 |
|
|
1949 |
### waitForText |
|
1950 |
|
|
1951 |
Waits up to $timeout seconds for the given string to appear on the page. |
|
1952 |
|
|
1953 |
Can also be passed a selector to search in, be as specific as possible when using selectors. |
|
1954 |
waitForText() will only watch the first instance of the matching selector / text provided. |
|
1955 |
If the given text doesn't appear, a timeout exception is thrown. |
|
1956 |
|
|
1957 |
``` php |
|
1958 |
<?php |
|
1959 |
$I->waitForText('foo', 30); // secs |
|
1960 |
$I->waitForText('foo', 30, '.title'); // secs |
|
1961 |
?> |
|
1962 |
``` |
|
1963 |
|
|
1964 |
* `param string` $text |
|
1965 |
* `param int` $timeout seconds |
|
1966 |
* `param string` $selector optional |
|
1967 |
@throws \Exception |
|
1968 |
|
|
1969 |
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.5/src/Codeception/Module/AngularJS.php">Help us to improve documentation. Edit module reference</a></div> |