commit | author | age
|
2207d6
|
1 |
# ZendExpressive |
W |
2 |
|
|
3 |
|
|
4 |
This module allows you to run tests inside Zend Expressive. |
|
5 |
|
|
6 |
Uses `config/container.php` file by default. |
|
7 |
|
|
8 |
## Status |
|
9 |
|
|
10 |
* Maintainer: **Naktibalda** |
|
11 |
* Stability: **alpha** |
|
12 |
|
|
13 |
## Config |
|
14 |
|
|
15 |
* container: relative path to file which returns Container (default: `config/container.php`) |
|
16 |
|
|
17 |
## API |
|
18 |
|
|
19 |
* application - instance of `\Zend\Expressive\Application` |
|
20 |
* container - instance of `\Interop\Container\ContainerInterface` |
|
21 |
* client - BrowserKit client |
|
22 |
|
|
23 |
|
|
24 |
## Actions |
|
25 |
|
|
26 |
### _findElements |
|
27 |
|
|
28 |
*hidden API method, expected to be used from Helper classes* |
|
29 |
|
|
30 |
Locates element using available Codeception locator types: |
|
31 |
|
|
32 |
* XPath |
|
33 |
* CSS |
|
34 |
* Strict Locator |
|
35 |
|
|
36 |
Use it in Helpers or GroupObject or Extension classes: |
|
37 |
|
|
38 |
```php |
|
39 |
<?php |
|
40 |
$els = $this->getModule('ZendExpressive')->_findElements('.items'); |
|
41 |
$els = $this->getModule('ZendExpressive')->_findElements(['name' => 'username']); |
|
42 |
|
|
43 |
$editLinks = $this->getModule('ZendExpressive')->_findElements(['link' => 'Edit']); |
|
44 |
// now you can iterate over $editLinks and check that all them have valid hrefs |
|
45 |
``` |
|
46 |
|
|
47 |
WebDriver module returns `Facebook\WebDriver\Remote\RemoteWebElement` instances |
|
48 |
PhpBrowser and Framework modules return `Symfony\Component\DomCrawler\Crawler` instances |
|
49 |
|
|
50 |
* `param` $locator |
|
51 |
* `return` array of interactive elements |
|
52 |
|
|
53 |
|
|
54 |
### _getResponseContent |
|
55 |
|
|
56 |
*hidden API method, expected to be used from Helper classes* |
|
57 |
|
|
58 |
Returns content of the last response |
|
59 |
Use it in Helpers when you want to retrieve response of request performed by another module. |
|
60 |
|
|
61 |
```php |
|
62 |
<?php |
|
63 |
// in Helper class |
|
64 |
public function seeResponseContains($text) |
|
65 |
{ |
|
66 |
$this->assertContains($text, $this->getModule('ZendExpressive')->_getResponseContent(), "response contains"); |
|
67 |
} |
|
68 |
?> |
|
69 |
``` |
|
70 |
|
|
71 |
* `return` string |
|
72 |
@throws ModuleException |
|
73 |
|
|
74 |
|
|
75 |
### _loadPage |
|
76 |
|
|
77 |
*hidden API method, expected to be used from Helper classes* |
|
78 |
|
|
79 |
Opens a page with arbitrary request parameters. |
|
80 |
Useful for testing multi-step forms on a specific step. |
|
81 |
|
|
82 |
```php |
|
83 |
<?php |
|
84 |
// in Helper class |
|
85 |
public function openCheckoutFormStep2($orderId) { |
|
86 |
$this->getModule('ZendExpressive')->_loadPage('POST', '/checkout/step2', ['order' => $orderId]); |
|
87 |
} |
|
88 |
?> |
|
89 |
``` |
|
90 |
|
|
91 |
* `param` $method |
|
92 |
* `param` $uri |
|
93 |
* `param array` $parameters |
|
94 |
* `param array` $files |
|
95 |
* `param array` $server |
|
96 |
* `param null` $content |
|
97 |
|
|
98 |
|
|
99 |
### _request |
|
100 |
|
|
101 |
*hidden API method, expected to be used from Helper classes* |
|
102 |
|
|
103 |
Send custom request to a backend using method, uri, parameters, etc. |
|
104 |
Use it in Helpers to create special request actions, like accessing API |
|
105 |
Returns a string with response body. |
|
106 |
|
|
107 |
```php |
|
108 |
<?php |
|
109 |
// in Helper class |
|
110 |
public function createUserByApi($name) { |
|
111 |
$userData = $this->getModule('ZendExpressive')->_request('POST', '/api/v1/users', ['name' => $name]); |
|
112 |
$user = json_decode($userData); |
|
113 |
return $user->id; |
|
114 |
} |
|
115 |
?> |
|
116 |
``` |
|
117 |
Does not load the response into the module so you can't interact with response page (click, fill forms). |
|
118 |
To load arbitrary page for interaction, use `_loadPage` method. |
|
119 |
|
|
120 |
* `param` $method |
|
121 |
* `param` $uri |
|
122 |
* `param array` $parameters |
|
123 |
* `param array` $files |
|
124 |
* `param array` $server |
|
125 |
* `param null` $content |
|
126 |
* `return` mixed|Crawler |
|
127 |
@throws ExternalUrlException |
|
128 |
@see `_loadPage` |
|
129 |
|
|
130 |
|
|
131 |
### _savePageSource |
|
132 |
|
|
133 |
*hidden API method, expected to be used from Helper classes* |
|
134 |
|
|
135 |
Saves page source of to a file |
|
136 |
|
|
137 |
```php |
|
138 |
$this->getModule('ZendExpressive')->_savePageSource(codecept_output_dir().'page.html'); |
|
139 |
``` |
|
140 |
* `param` $filename |
|
141 |
|
|
142 |
|
|
143 |
### amHttpAuthenticated |
|
144 |
|
|
145 |
Authenticates user for HTTP_AUTH |
|
146 |
|
|
147 |
* `param` $username |
|
148 |
* `param` $password |
|
149 |
|
|
150 |
|
|
151 |
### amOnPage |
|
152 |
|
|
153 |
Opens the page for the given relative URI. |
|
154 |
|
|
155 |
``` php |
|
156 |
<?php |
|
157 |
// opens front page |
|
158 |
$I->amOnPage('/'); |
|
159 |
// opens /register page |
|
160 |
$I->amOnPage('/register'); |
|
161 |
``` |
|
162 |
|
|
163 |
* `param string` $page |
|
164 |
|
|
165 |
|
|
166 |
### attachFile |
|
167 |
|
|
168 |
Attaches a file relative to the Codeception `_data` directory to the given file upload field. |
|
169 |
|
|
170 |
``` php |
|
171 |
<?php |
|
172 |
// file is stored in 'tests/_data/prices.xls' |
|
173 |
$I->attachFile('input[@type="file"]', 'prices.xls'); |
|
174 |
?> |
|
175 |
``` |
|
176 |
|
|
177 |
* `param` $field |
|
178 |
* `param` $filename |
|
179 |
|
|
180 |
|
|
181 |
### checkOption |
|
182 |
|
|
183 |
Ticks a checkbox. For radio buttons, use the `selectOption` method instead. |
|
184 |
|
|
185 |
``` php |
|
186 |
<?php |
|
187 |
$I->checkOption('#agree'); |
|
188 |
?> |
|
189 |
``` |
|
190 |
|
|
191 |
* `param` $option |
|
192 |
|
|
193 |
|
|
194 |
### click |
|
195 |
|
|
196 |
Perform a click on a link or a button, given by a locator. |
|
197 |
If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. |
|
198 |
For buttons, the "value" attribute, "name" attribute, and inner text are searched. |
|
199 |
For links, the link text is searched. |
|
200 |
For images, the "alt" attribute and inner text of any parent links are searched. |
|
201 |
|
|
202 |
The second parameter is a context (CSS or XPath locator) to narrow the search. |
|
203 |
|
|
204 |
Note that if the locator matches a button of type `submit`, the form will be submitted. |
|
205 |
|
|
206 |
``` php |
|
207 |
<?php |
|
208 |
// simple link |
|
209 |
$I->click('Logout'); |
|
210 |
// button of form |
|
211 |
$I->click('Submit'); |
|
212 |
// CSS button |
|
213 |
$I->click('#form input[type=submit]'); |
|
214 |
// XPath |
|
215 |
$I->click('//form/*[@type=submit]'); |
|
216 |
// link in context |
|
217 |
$I->click('Logout', '#nav'); |
|
218 |
// using strict locator |
|
219 |
$I->click(['link' => 'Login']); |
|
220 |
?> |
|
221 |
``` |
|
222 |
|
|
223 |
* `param` $link |
|
224 |
* `param` $context |
|
225 |
|
|
226 |
|
|
227 |
### deleteHeader |
|
228 |
|
|
229 |
Deletes the header with the passed name. Subsequent requests |
|
230 |
will not have the deleted header in its request. |
|
231 |
|
|
232 |
Example: |
|
233 |
```php |
|
234 |
<?php |
|
235 |
$I->haveHttpHeader('X-Requested-With', 'Codeception'); |
|
236 |
$I->amOnPage('test-headers.php'); |
|
237 |
// ... |
|
238 |
$I->deleteHeader('X-Requested-With'); |
|
239 |
$I->amOnPage('some-other-page.php'); |
|
240 |
?> |
|
241 |
``` |
|
242 |
|
|
243 |
* `param string` $name the name of the header to delete. |
|
244 |
|
|
245 |
|
|
246 |
### dontSee |
|
247 |
|
|
248 |
Checks that the current page doesn't contain the text specified (case insensitive). |
|
249 |
Give a locator as the second parameter to match a specific region. |
|
250 |
|
|
251 |
```php |
|
252 |
<?php |
|
253 |
$I->dontSee('Login'); // I can suppose user is already logged in |
|
254 |
$I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page |
|
255 |
$I->dontSee('Sign Up','//body/h1'); // with XPath |
|
256 |
$I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator |
|
257 |
``` |
|
258 |
|
|
259 |
Note that the search is done after stripping all HTML tags from the body, |
|
260 |
so `$I->dontSee('strong')` will fail on strings like: |
|
261 |
|
|
262 |
- `<p>I am Stronger than thou</p>` |
|
263 |
- `<script>document.createElement('strong');</script>` |
|
264 |
|
|
265 |
But will ignore strings like: |
|
266 |
|
|
267 |
- `<strong>Home</strong>` |
|
268 |
- `<div class="strong">Home</strong>` |
|
269 |
- `<!-- strong -->` |
|
270 |
|
|
271 |
For checking the raw source code, use `seeInSource()`. |
|
272 |
|
|
273 |
* `param string` $text |
|
274 |
* `param string` $selector optional |
|
275 |
|
|
276 |
|
|
277 |
### dontSeeCheckboxIsChecked |
|
278 |
|
|
279 |
Check that the specified checkbox is unchecked. |
|
280 |
|
|
281 |
``` php |
|
282 |
<?php |
|
283 |
$I->dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms |
|
284 |
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. |
|
285 |
?> |
|
286 |
``` |
|
287 |
|
|
288 |
* `param` $checkbox |
|
289 |
|
|
290 |
|
|
291 |
### dontSeeCookie |
|
292 |
|
|
293 |
Checks that there isn't a cookie with the given name. |
|
294 |
You can set additional cookie params like `domain`, `path` as array passed in last argument. |
|
295 |
|
|
296 |
* `param` $cookie |
|
297 |
|
|
298 |
* `param array` $params |
|
299 |
|
|
300 |
|
|
301 |
### dontSeeCurrentUrlEquals |
|
302 |
|
|
303 |
Checks that the current URL doesn't equal the given string. |
|
304 |
Unlike `dontSeeInCurrentUrl`, this only matches the full URL. |
|
305 |
|
|
306 |
``` php |
|
307 |
<?php |
|
308 |
// current url is not root |
|
309 |
$I->dontSeeCurrentUrlEquals('/'); |
|
310 |
?> |
|
311 |
``` |
|
312 |
|
|
313 |
* `param string` $uri |
|
314 |
|
|
315 |
|
|
316 |
### dontSeeCurrentUrlMatches |
|
317 |
|
|
318 |
Checks that current url doesn't match the given regular expression. |
|
319 |
|
|
320 |
``` php |
|
321 |
<?php |
|
322 |
// to match root url |
|
323 |
$I->dontSeeCurrentUrlMatches('~^/users/(\d+)~'); |
|
324 |
?> |
|
325 |
``` |
|
326 |
|
|
327 |
* `param string` $uri |
|
328 |
|
|
329 |
|
|
330 |
### dontSeeElement |
|
331 |
|
|
332 |
Checks that the given element is invisible or not present on the page. |
|
333 |
You can also specify expected attributes of this element. |
|
334 |
|
|
335 |
``` php |
|
336 |
<?php |
|
337 |
$I->dontSeeElement('.error'); |
|
338 |
$I->dontSeeElement('//form/input[1]'); |
|
339 |
$I->dontSeeElement('input', ['name' => 'login']); |
|
340 |
$I->dontSeeElement('input', ['value' => '123456']); |
|
341 |
?> |
|
342 |
``` |
|
343 |
|
|
344 |
* `param` $selector |
|
345 |
* `param array` $attributes |
|
346 |
|
|
347 |
|
|
348 |
### dontSeeInCurrentUrl |
|
349 |
|
|
350 |
Checks that the current URI doesn't contain the given string. |
|
351 |
|
|
352 |
``` php |
|
353 |
<?php |
|
354 |
$I->dontSeeInCurrentUrl('/users/'); |
|
355 |
?> |
|
356 |
``` |
|
357 |
|
|
358 |
* `param string` $uri |
|
359 |
|
|
360 |
|
|
361 |
### dontSeeInField |
|
362 |
|
|
363 |
Checks that an input field or textarea doesn't contain the given value. |
|
364 |
For fuzzy locators, the field is matched by label text, CSS and XPath. |
|
365 |
|
|
366 |
``` php |
|
367 |
<?php |
|
368 |
$I->dontSeeInField('Body','Type your comment here'); |
|
369 |
$I->dontSeeInField('form textarea[name=body]','Type your comment here'); |
|
370 |
$I->dontSeeInField('form input[type=hidden]','hidden_value'); |
|
371 |
$I->dontSeeInField('#searchform input','Search'); |
|
372 |
$I->dontSeeInField('//form/*[@name=search]','Search'); |
|
373 |
$I->dontSeeInField(['name' => 'search'], 'Search'); |
|
374 |
?> |
|
375 |
``` |
|
376 |
|
|
377 |
* `param` $field |
|
378 |
* `param` $value |
|
379 |
|
|
380 |
|
|
381 |
### dontSeeInFormFields |
|
382 |
|
|
383 |
Checks if the array of form parameters (name => value) are not set on the form matched with |
|
384 |
the passed selector. |
|
385 |
|
|
386 |
``` php |
|
387 |
<?php |
|
388 |
$I->dontSeeInFormFields('form[name=myform]', [ |
|
389 |
'input1' => 'non-existent value', |
|
390 |
'input2' => 'other non-existent value', |
|
391 |
]); |
|
392 |
?> |
|
393 |
``` |
|
394 |
|
|
395 |
To check that an element hasn't been assigned any one of many values, an array can be passed |
|
396 |
as the value: |
|
397 |
|
|
398 |
``` php |
|
399 |
<?php |
|
400 |
$I->dontSeeInFormFields('.form-class', [ |
|
401 |
'fieldName' => [ |
|
402 |
'This value shouldn\'t be set', |
|
403 |
'And this value shouldn\'t be set', |
|
404 |
], |
|
405 |
]); |
|
406 |
?> |
|
407 |
``` |
|
408 |
|
|
409 |
Additionally, checkbox values can be checked with a boolean. |
|
410 |
|
|
411 |
``` php |
|
412 |
<?php |
|
413 |
$I->dontSeeInFormFields('#form-id', [ |
|
414 |
'checkbox1' => true, // fails if checked |
|
415 |
'checkbox2' => false, // fails if unchecked |
|
416 |
]); |
|
417 |
?> |
|
418 |
``` |
|
419 |
|
|
420 |
* `param` $formSelector |
|
421 |
* `param` $params |
|
422 |
|
|
423 |
|
|
424 |
### dontSeeInSource |
|
425 |
|
|
426 |
Checks that the current page contains the given string in its |
|
427 |
raw source code. |
|
428 |
|
|
429 |
```php |
|
430 |
<?php |
|
431 |
$I->dontSeeInSource('<h1>Green eggs & ham</h1>'); |
|
432 |
``` |
|
433 |
|
|
434 |
* `param` $raw |
|
435 |
|
|
436 |
|
|
437 |
### dontSeeInTitle |
|
438 |
|
|
439 |
Checks that the page title does not contain the given string. |
|
440 |
|
|
441 |
* `param` $title |
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
### dontSeeLink |
|
446 |
|
|
447 |
Checks that the page doesn't contain a link with the given string. |
|
448 |
If the second parameter is given, only links with a matching "href" attribute will be checked. |
|
449 |
|
|
450 |
``` php |
|
451 |
<?php |
|
452 |
$I->dontSeeLink('Logout'); // I suppose user is not logged in |
|
453 |
$I->dontSeeLink('Checkout now', '/store/cart.php'); |
|
454 |
?> |
|
455 |
``` |
|
456 |
|
|
457 |
* `param string` $text |
|
458 |
* `param string` $url optional |
|
459 |
|
|
460 |
|
|
461 |
### dontSeeOptionIsSelected |
|
462 |
|
|
463 |
Checks that the given option is not selected. |
|
464 |
|
|
465 |
``` php |
|
466 |
<?php |
|
467 |
$I->dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); |
|
468 |
?> |
|
469 |
``` |
|
470 |
|
|
471 |
* `param` $selector |
|
472 |
* `param` $optionText |
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
### dontSeeResponseCodeIs |
|
477 |
|
|
478 |
Checks that response code is equal to value provided. |
|
479 |
|
|
480 |
```php |
|
481 |
<?php |
|
482 |
$I->dontSeeResponseCodeIs(200); |
|
483 |
|
|
484 |
// recommended \Codeception\Util\HttpCode |
|
485 |
$I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); |
|
486 |
``` |
|
487 |
* `param` $code |
|
488 |
|
|
489 |
|
|
490 |
### fillField |
|
491 |
|
|
492 |
Fills a text field or textarea with the given string. |
|
493 |
|
|
494 |
``` php |
|
495 |
<?php |
|
496 |
$I->fillField("//input[@type='text']", "Hello World!"); |
|
497 |
$I->fillField(['name' => 'email'], 'jon@mail.com'); |
|
498 |
?> |
|
499 |
``` |
|
500 |
|
|
501 |
* `param` $field |
|
502 |
* `param` $value |
|
503 |
|
|
504 |
|
|
505 |
### grabAttributeFrom |
|
506 |
|
|
507 |
Grabs the value of the given attribute value from the given element. |
|
508 |
Fails if element is not found. |
|
509 |
|
|
510 |
``` php |
|
511 |
<?php |
|
512 |
$I->grabAttributeFrom('#tooltip', 'title'); |
|
513 |
?> |
|
514 |
``` |
|
515 |
|
|
516 |
* `param` $cssOrXpath |
|
517 |
* `param` $attribute |
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
### grabCookie |
|
522 |
|
|
523 |
Grabs a cookie value. |
|
524 |
You can set additional cookie params like `domain`, `path` in array passed as last argument. |
|
525 |
|
|
526 |
* `param` $cookie |
|
527 |
|
|
528 |
* `param array` $params |
|
529 |
|
|
530 |
|
|
531 |
### grabFromCurrentUrl |
|
532 |
|
|
533 |
Executes the given regular expression against the current URI and returns the first capturing group. |
|
534 |
If no parameters are provided, the full URI is returned. |
|
535 |
|
|
536 |
``` php |
|
537 |
<?php |
|
538 |
$user_id = $I->grabFromCurrentUrl('~^/user/(\d+)/~'); |
|
539 |
$uri = $I->grabFromCurrentUrl(); |
|
540 |
?> |
|
541 |
``` |
|
542 |
|
|
543 |
* `param string` $uri optional |
|
544 |
|
|
545 |
|
|
546 |
|
|
547 |
### grabMultiple |
|
548 |
|
|
549 |
Grabs either the text content, or attribute values, of nodes |
|
550 |
matched by $cssOrXpath and returns them as an array. |
|
551 |
|
|
552 |
```html |
|
553 |
<a href="#first">First</a> |
|
554 |
<a href="#second">Second</a> |
|
555 |
<a href="#third">Third</a> |
|
556 |
``` |
|
557 |
|
|
558 |
```php |
|
559 |
<?php |
|
560 |
// would return ['First', 'Second', 'Third'] |
|
561 |
$aLinkText = $I->grabMultiple('a'); |
|
562 |
|
|
563 |
// would return ['#first', '#second', '#third'] |
|
564 |
$aLinks = $I->grabMultiple('a', 'href'); |
|
565 |
?> |
|
566 |
``` |
|
567 |
|
|
568 |
* `param` $cssOrXpath |
|
569 |
* `param` $attribute |
|
570 |
* `return` string[] |
|
571 |
|
|
572 |
|
|
573 |
### grabPageSource |
|
574 |
|
|
575 |
Grabs current page source code. |
|
576 |
|
|
577 |
@throws ModuleException if no page was opened. |
|
578 |
|
|
579 |
* `return` string Current page source code. |
|
580 |
|
|
581 |
|
|
582 |
### grabTextFrom |
|
583 |
|
|
584 |
Finds and returns the text contents of the given element. |
|
585 |
If a fuzzy locator is used, the element is found using CSS, XPath, |
|
586 |
and by matching the full page source by regular expression. |
|
587 |
|
|
588 |
``` php |
|
589 |
<?php |
|
590 |
$heading = $I->grabTextFrom('h1'); |
|
591 |
$heading = $I->grabTextFrom('descendant-or-self::h1'); |
|
592 |
$value = $I->grabTextFrom('~<input value=(.*?)]~sgi'); // match with a regex |
|
593 |
?> |
|
594 |
``` |
|
595 |
|
|
596 |
* `param` $cssOrXPathOrRegex |
|
597 |
|
|
598 |
|
|
599 |
|
|
600 |
### grabValueFrom |
|
601 |
|
|
602 |
* `param` $field |
|
603 |
|
|
604 |
* `return` array|mixed|null|string |
|
605 |
|
|
606 |
|
|
607 |
### haveHttpHeader |
|
608 |
|
|
609 |
Sets the HTTP header to the passed value - which is used on |
|
610 |
subsequent HTTP requests through PhpBrowser. |
|
611 |
|
|
612 |
Example: |
|
613 |
```php |
|
614 |
<?php |
|
615 |
$I->haveHttpHeader('X-Requested-With', 'Codeception'); |
|
616 |
$I->amOnPage('test-headers.php'); |
|
617 |
?> |
|
618 |
``` |
|
619 |
|
|
620 |
To use special chars in Header Key use HTML Character Entities: |
|
621 |
Example: |
|
622 |
Header with underscore - 'Client_Id' |
|
623 |
should be represented as - 'Client_Id' or 'Client_Id' |
|
624 |
|
|
625 |
```php |
|
626 |
<?php |
|
627 |
$I->haveHttpHeader('Client_Id', 'Codeception'); |
|
628 |
?> |
|
629 |
``` |
|
630 |
|
|
631 |
* `param string` $name the name of the request header |
|
632 |
* `param string` $value the value to set it to for subsequent |
|
633 |
requests |
|
634 |
|
|
635 |
|
|
636 |
### moveBack |
|
637 |
|
|
638 |
Moves back in history. |
|
639 |
|
|
640 |
* `param int` $numberOfSteps (default value 1) |
|
641 |
|
|
642 |
|
|
643 |
### resetCookie |
|
644 |
|
|
645 |
Unsets cookie with the given name. |
|
646 |
You can set additional cookie params like `domain`, `path` in array passed as last argument. |
|
647 |
|
|
648 |
* `param` $cookie |
|
649 |
|
|
650 |
* `param array` $params |
|
651 |
|
|
652 |
|
|
653 |
### see |
|
654 |
|
|
655 |
Checks that the current page contains the given string (case insensitive). |
|
656 |
|
|
657 |
You can specify a specific HTML element (via CSS or XPath) as the second |
|
658 |
parameter to only search within that element. |
|
659 |
|
|
660 |
``` php |
|
661 |
<?php |
|
662 |
$I->see('Logout'); // I can suppose user is logged in |
|
663 |
$I->see('Sign Up', 'h1'); // I can suppose it's a signup page |
|
664 |
$I->see('Sign Up', '//body/h1'); // with XPath |
|
665 |
$I->see('Sign Up', ['css' => 'body h1']); // with strict CSS locator |
|
666 |
``` |
|
667 |
|
|
668 |
Note that the search is done after stripping all HTML tags from the body, |
|
669 |
so `$I->see('strong')` will return true for strings like: |
|
670 |
|
|
671 |
- `<p>I am Stronger than thou</p>` |
|
672 |
- `<script>document.createElement('strong');</script>` |
|
673 |
|
|
674 |
But will *not* be true for strings like: |
|
675 |
|
|
676 |
- `<strong>Home</strong>` |
|
677 |
- `<div class="strong">Home</strong>` |
|
678 |
- `<!-- strong -->` |
|
679 |
|
|
680 |
For checking the raw source code, use `seeInSource()`. |
|
681 |
|
|
682 |
* `param string` $text |
|
683 |
* `param string` $selector optional |
|
684 |
|
|
685 |
|
|
686 |
### seeCheckboxIsChecked |
|
687 |
|
|
688 |
Checks that the specified checkbox is checked. |
|
689 |
|
|
690 |
``` php |
|
691 |
<?php |
|
692 |
$I->seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms |
|
693 |
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. |
|
694 |
$I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); |
|
695 |
?> |
|
696 |
``` |
|
697 |
|
|
698 |
* `param` $checkbox |
|
699 |
|
|
700 |
|
|
701 |
### seeCookie |
|
702 |
|
|
703 |
Checks that a cookie with the given name is set. |
|
704 |
You can set additional cookie params like `domain`, `path` as array passed in last argument. |
|
705 |
|
|
706 |
``` php |
|
707 |
<?php |
|
708 |
$I->seeCookie('PHPSESSID'); |
|
709 |
?> |
|
710 |
``` |
|
711 |
|
|
712 |
* `param` $cookie |
|
713 |
* `param array` $params |
|
714 |
|
|
715 |
|
|
716 |
### seeCurrentUrlEquals |
|
717 |
|
|
718 |
Checks that the current URL is equal to the given string. |
|
719 |
Unlike `seeInCurrentUrl`, this only matches the full URL. |
|
720 |
|
|
721 |
``` php |
|
722 |
<?php |
|
723 |
// to match root url |
|
724 |
$I->seeCurrentUrlEquals('/'); |
|
725 |
?> |
|
726 |
``` |
|
727 |
|
|
728 |
* `param string` $uri |
|
729 |
|
|
730 |
|
|
731 |
### seeCurrentUrlMatches |
|
732 |
|
|
733 |
Checks that the current URL matches the given regular expression. |
|
734 |
|
|
735 |
``` php |
|
736 |
<?php |
|
737 |
// to match root url |
|
738 |
$I->seeCurrentUrlMatches('~^/users/(\d+)~'); |
|
739 |
?> |
|
740 |
``` |
|
741 |
|
|
742 |
* `param string` $uri |
|
743 |
|
|
744 |
|
|
745 |
### seeElement |
|
746 |
|
|
747 |
Checks that the given element exists on the page and is visible. |
|
748 |
You can also specify expected attributes of this element. |
|
749 |
|
|
750 |
``` php |
|
751 |
<?php |
|
752 |
$I->seeElement('.error'); |
|
753 |
$I->seeElement('//form/input[1]'); |
|
754 |
$I->seeElement('input', ['name' => 'login']); |
|
755 |
$I->seeElement('input', ['value' => '123456']); |
|
756 |
|
|
757 |
// strict locator in first arg, attributes in second |
|
758 |
$I->seeElement(['css' => 'form input'], ['name' => 'login']); |
|
759 |
?> |
|
760 |
``` |
|
761 |
|
|
762 |
* `param` $selector |
|
763 |
* `param array` $attributes |
|
764 |
@return |
|
765 |
|
|
766 |
|
|
767 |
### seeInCurrentUrl |
|
768 |
|
|
769 |
Checks that current URI contains the given string. |
|
770 |
|
|
771 |
``` php |
|
772 |
<?php |
|
773 |
// to match: /home/dashboard |
|
774 |
$I->seeInCurrentUrl('home'); |
|
775 |
// to match: /users/1 |
|
776 |
$I->seeInCurrentUrl('/users/'); |
|
777 |
?> |
|
778 |
``` |
|
779 |
|
|
780 |
* `param string` $uri |
|
781 |
|
|
782 |
|
|
783 |
### seeInField |
|
784 |
|
|
785 |
Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. |
|
786 |
Fields are matched by label text, the "name" attribute, CSS, or XPath. |
|
787 |
|
|
788 |
``` php |
|
789 |
<?php |
|
790 |
$I->seeInField('Body','Type your comment here'); |
|
791 |
$I->seeInField('form textarea[name=body]','Type your comment here'); |
|
792 |
$I->seeInField('form input[type=hidden]','hidden_value'); |
|
793 |
$I->seeInField('#searchform input','Search'); |
|
794 |
$I->seeInField('//form/*[@name=search]','Search'); |
|
795 |
$I->seeInField(['name' => 'search'], 'Search'); |
|
796 |
?> |
|
797 |
``` |
|
798 |
|
|
799 |
* `param` $field |
|
800 |
* `param` $value |
|
801 |
|
|
802 |
|
|
803 |
### seeInFormFields |
|
804 |
|
|
805 |
Checks if the array of form parameters (name => value) are set on the form matched with the |
|
806 |
passed selector. |
|
807 |
|
|
808 |
``` php |
|
809 |
<?php |
|
810 |
$I->seeInFormFields('form[name=myform]', [ |
|
811 |
'input1' => 'value', |
|
812 |
'input2' => 'other value', |
|
813 |
]); |
|
814 |
?> |
|
815 |
``` |
|
816 |
|
|
817 |
For multi-select elements, or to check values of multiple elements with the same name, an |
|
818 |
array may be passed: |
|
819 |
|
|
820 |
``` php |
|
821 |
<?php |
|
822 |
$I->seeInFormFields('.form-class', [ |
|
823 |
'multiselect' => [ |
|
824 |
'value1', |
|
825 |
'value2', |
|
826 |
], |
|
827 |
'checkbox[]' => [ |
|
828 |
'a checked value', |
|
829 |
'another checked value', |
|
830 |
], |
|
831 |
]); |
|
832 |
?> |
|
833 |
``` |
|
834 |
|
|
835 |
Additionally, checkbox values can be checked with a boolean. |
|
836 |
|
|
837 |
``` php |
|
838 |
<?php |
|
839 |
$I->seeInFormFields('#form-id', [ |
|
840 |
'checkbox1' => true, // passes if checked |
|
841 |
'checkbox2' => false, // passes if unchecked |
|
842 |
]); |
|
843 |
?> |
|
844 |
``` |
|
845 |
|
|
846 |
Pair this with submitForm for quick testing magic. |
|
847 |
|
|
848 |
``` php |
|
849 |
<?php |
|
850 |
$form = [ |
|
851 |
'field1' => 'value', |
|
852 |
'field2' => 'another value', |
|
853 |
'checkbox1' => true, |
|
854 |
// ... |
|
855 |
]; |
|
856 |
$I->submitForm('//form[@id=my-form]', $form, 'submitButton'); |
|
857 |
// $I->amOnPage('/path/to/form-page') may be needed |
|
858 |
$I->seeInFormFields('//form[@id=my-form]', $form); |
|
859 |
?> |
|
860 |
``` |
|
861 |
|
|
862 |
* `param` $formSelector |
|
863 |
* `param` $params |
|
864 |
|
|
865 |
|
|
866 |
### seeInSource |
|
867 |
|
|
868 |
Checks that the current page contains the given string in its |
|
869 |
raw source code. |
|
870 |
|
|
871 |
``` php |
|
872 |
<?php |
|
873 |
$I->seeInSource('<h1>Green eggs & ham</h1>'); |
|
874 |
``` |
|
875 |
|
|
876 |
* `param` $raw |
|
877 |
|
|
878 |
|
|
879 |
### seeInTitle |
|
880 |
|
|
881 |
Checks that the page title contains the given string. |
|
882 |
|
|
883 |
``` php |
|
884 |
<?php |
|
885 |
$I->seeInTitle('Blog - Post #1'); |
|
886 |
?> |
|
887 |
``` |
|
888 |
|
|
889 |
* `param` $title |
|
890 |
|
|
891 |
|
|
892 |
|
|
893 |
### seeLink |
|
894 |
|
|
895 |
Checks that there's a link with the specified text. |
|
896 |
Give a full URL as the second parameter to match links with that exact URL. |
|
897 |
|
|
898 |
``` php |
|
899 |
<?php |
|
900 |
$I->seeLink('Logout'); // matches <a href="#">Logout</a> |
|
901 |
$I->seeLink('Logout','/logout'); // matches <a href="/logout">Logout</a> |
|
902 |
?> |
|
903 |
``` |
|
904 |
|
|
905 |
* `param string` $text |
|
906 |
* `param string` $url optional |
|
907 |
|
|
908 |
|
|
909 |
### seeNumberOfElements |
|
910 |
|
|
911 |
Checks that there are a certain number of elements matched by the given locator on the page. |
|
912 |
|
|
913 |
``` php |
|
914 |
<?php |
|
915 |
$I->seeNumberOfElements('tr', 10); |
|
916 |
$I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements |
|
917 |
?> |
|
918 |
``` |
|
919 |
* `param` $selector |
|
920 |
* `param mixed` $expected int or int[] |
|
921 |
|
|
922 |
|
|
923 |
### seeOptionIsSelected |
|
924 |
|
|
925 |
Checks that the given option is selected. |
|
926 |
|
|
927 |
``` php |
|
928 |
<?php |
|
929 |
$I->seeOptionIsSelected('#form input[name=payment]', 'Visa'); |
|
930 |
?> |
|
931 |
``` |
|
932 |
|
|
933 |
* `param` $selector |
|
934 |
* `param` $optionText |
|
935 |
|
|
936 |
|
|
937 |
|
|
938 |
### seePageNotFound |
|
939 |
|
|
940 |
Asserts that current page has 404 response status code. |
|
941 |
|
|
942 |
|
|
943 |
### seeResponseCodeIs |
|
944 |
|
|
945 |
Checks that response code is equal to value provided. |
|
946 |
|
|
947 |
```php |
|
948 |
<?php |
|
949 |
$I->seeResponseCodeIs(200); |
|
950 |
|
|
951 |
// recommended \Codeception\Util\HttpCode |
|
952 |
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); |
|
953 |
``` |
|
954 |
|
|
955 |
* `param` $code |
|
956 |
|
|
957 |
|
|
958 |
### seeResponseCodeIsBetween |
|
959 |
|
|
960 |
Checks that response code is between a certain range. Between actually means [from <= CODE <= to] |
|
961 |
|
|
962 |
* `param` $from |
|
963 |
* `param` $to |
|
964 |
|
|
965 |
|
|
966 |
### seeResponseCodeIsClientError |
|
967 |
|
|
968 |
Checks that the response code is 4xx |
|
969 |
|
|
970 |
|
|
971 |
### seeResponseCodeIsRedirection |
|
972 |
|
|
973 |
Checks that the response code 3xx |
|
974 |
|
|
975 |
|
|
976 |
### seeResponseCodeIsServerError |
|
977 |
|
|
978 |
Checks that the response code is 5xx |
|
979 |
|
|
980 |
|
|
981 |
### seeResponseCodeIsSuccessful |
|
982 |
|
|
983 |
Checks that the response code 2xx |
|
984 |
|
|
985 |
|
|
986 |
### selectOption |
|
987 |
|
|
988 |
Selects an option in a select tag or in radio button group. |
|
989 |
|
|
990 |
``` php |
|
991 |
<?php |
|
992 |
$I->selectOption('form select[name=account]', 'Premium'); |
|
993 |
$I->selectOption('form input[name=payment]', 'Monthly'); |
|
994 |
$I->selectOption('//form/select[@name=account]', 'Monthly'); |
|
995 |
?> |
|
996 |
``` |
|
997 |
|
|
998 |
Provide an array for the second argument to select multiple options: |
|
999 |
|
|
1000 |
``` php |
|
1001 |
<?php |
|
1002 |
$I->selectOption('Which OS do you use?', array('Windows','Linux')); |
|
1003 |
?> |
|
1004 |
``` |
|
1005 |
|
|
1006 |
Or provide an associative array for the second argument to specifically define which selection method should be used: |
|
1007 |
|
|
1008 |
``` php |
|
1009 |
<?php |
|
1010 |
$I->selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' |
|
1011 |
$I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' |
|
1012 |
?> |
|
1013 |
``` |
|
1014 |
|
|
1015 |
* `param` $select |
|
1016 |
* `param` $option |
|
1017 |
|
|
1018 |
|
|
1019 |
### sendAjaxGetRequest |
|
1020 |
|
|
1021 |
If your page triggers an ajax request, you can perform it manually. |
|
1022 |
This action sends a GET ajax request with specified params. |
|
1023 |
|
|
1024 |
See ->sendAjaxPostRequest for examples. |
|
1025 |
|
|
1026 |
* `param` $uri |
|
1027 |
* `param` $params |
|
1028 |
|
|
1029 |
|
|
1030 |
### sendAjaxPostRequest |
|
1031 |
|
|
1032 |
If your page triggers an ajax request, you can perform it manually. |
|
1033 |
This action sends a POST ajax request with specified params. |
|
1034 |
Additional params can be passed as array. |
|
1035 |
|
|
1036 |
Example: |
|
1037 |
|
|
1038 |
Imagine that by clicking checkbox you trigger ajax request which updates user settings. |
|
1039 |
We emulate that click by running this ajax request manually. |
|
1040 |
|
|
1041 |
``` php |
|
1042 |
<?php |
|
1043 |
$I->sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST |
|
1044 |
$I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET |
|
1045 |
|
|
1046 |
``` |
|
1047 |
|
|
1048 |
* `param` $uri |
|
1049 |
* `param` $params |
|
1050 |
|
|
1051 |
|
|
1052 |
### sendAjaxRequest |
|
1053 |
|
|
1054 |
If your page triggers an ajax request, you can perform it manually. |
|
1055 |
This action sends an ajax request with specified method and params. |
|
1056 |
|
|
1057 |
Example: |
|
1058 |
|
|
1059 |
You need to perform an ajax request specifying the HTTP method. |
|
1060 |
|
|
1061 |
``` php |
|
1062 |
<?php |
|
1063 |
$I->sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title')); |
|
1064 |
|
|
1065 |
``` |
|
1066 |
|
|
1067 |
* `param` $method |
|
1068 |
* `param` $uri |
|
1069 |
* `param` $params |
|
1070 |
|
|
1071 |
|
|
1072 |
### setCookie |
|
1073 |
|
|
1074 |
Sets a cookie with the given name and value. |
|
1075 |
You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. |
|
1076 |
|
|
1077 |
``` php |
|
1078 |
<?php |
|
1079 |
$I->setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); |
|
1080 |
?> |
|
1081 |
``` |
|
1082 |
|
|
1083 |
* `param` $name |
|
1084 |
* `param` $val |
|
1085 |
* `param array` $params |
|
1086 |
|
|
1087 |
|
|
1088 |
|
|
1089 |
### submitForm |
|
1090 |
|
|
1091 |
Submits the given form on the page, with the given form |
|
1092 |
values. Pass the form field's values as an array in the second |
|
1093 |
parameter. |
|
1094 |
|
|
1095 |
Although this function can be used as a short-hand version of |
|
1096 |
`fillField()`, `selectOption()`, `click()` etc. it has some important |
|
1097 |
differences: |
|
1098 |
|
|
1099 |
* Only field *names* may be used, not CSS/XPath selectors nor field labels |
|
1100 |
* If a field is sent to this function that does *not* exist on the page, |
|
1101 |
it will silently be added to the HTTP request. This is helpful for testing |
|
1102 |
some types of forms, but be aware that you will *not* get an exception |
|
1103 |
like you would if you called `fillField()` or `selectOption()` with |
|
1104 |
a missing field. |
|
1105 |
|
|
1106 |
Fields that are not provided will be filled by their values from the page, |
|
1107 |
or from any previous calls to `fillField()`, `selectOption()` etc. |
|
1108 |
You don't need to click the 'Submit' button afterwards. |
|
1109 |
This command itself triggers the request to form's action. |
|
1110 |
|
|
1111 |
You can optionally specify which button's value to include |
|
1112 |
in the request with the last parameter (as an alternative to |
|
1113 |
explicitly setting its value in the second parameter), as |
|
1114 |
button values are not otherwise included in the request. |
|
1115 |
|
|
1116 |
Examples: |
|
1117 |
|
|
1118 |
``` php |
|
1119 |
<?php |
|
1120 |
$I->submitForm('#login', [ |
|
1121 |
'login' => 'davert', |
|
1122 |
'password' => '123456' |
|
1123 |
]); |
|
1124 |
// or |
|
1125 |
$I->submitForm('#login', [ |
|
1126 |
'login' => 'davert', |
|
1127 |
'password' => '123456' |
|
1128 |
], 'submitButtonName'); |
|
1129 |
|
|
1130 |
``` |
|
1131 |
|
|
1132 |
For example, given this sample "Sign Up" form: |
|
1133 |
|
|
1134 |
``` html |
|
1135 |
<form action="/sign_up"> |
|
1136 |
Login: |
|
1137 |
<input type="text" name="user[login]" /><br/> |
|
1138 |
Password: |
|
1139 |
<input type="password" name="user[password]" /><br/> |
|
1140 |
Do you agree to our terms? |
|
1141 |
<input type="checkbox" name="user[agree]" /><br/> |
|
1142 |
Select pricing plan: |
|
1143 |
<select name="plan"> |
|
1144 |
<option value="1">Free</option> |
|
1145 |
<option value="2" selected="selected">Paid</option> |
|
1146 |
</select> |
|
1147 |
<input type="submit" name="submitButton" value="Submit" /> |
|
1148 |
</form> |
|
1149 |
``` |
|
1150 |
|
|
1151 |
You could write the following to submit it: |
|
1152 |
|
|
1153 |
``` php |
|
1154 |
<?php |
|
1155 |
$I->submitForm( |
|
1156 |
'#userForm', |
|
1157 |
[ |
|
1158 |
'user' => [ |
|
1159 |
'login' => 'Davert', |
|
1160 |
'password' => '123456', |
|
1161 |
'agree' => true |
|
1162 |
] |
|
1163 |
], |
|
1164 |
'submitButton' |
|
1165 |
); |
|
1166 |
``` |
|
1167 |
Note that "2" will be the submitted value for the "plan" field, as it is |
|
1168 |
the selected option. |
|
1169 |
|
|
1170 |
You can also emulate a JavaScript submission by not specifying any |
|
1171 |
buttons in the third parameter to submitForm. |
|
1172 |
|
|
1173 |
```php |
|
1174 |
<?php |
|
1175 |
$I->submitForm( |
|
1176 |
'#userForm', |
|
1177 |
[ |
|
1178 |
'user' => [ |
|
1179 |
'login' => 'Davert', |
|
1180 |
'password' => '123456', |
|
1181 |
'agree' => true |
|
1182 |
] |
|
1183 |
] |
|
1184 |
); |
|
1185 |
``` |
|
1186 |
|
|
1187 |
This function works well when paired with `seeInFormFields()` |
|
1188 |
for quickly testing CRUD interfaces and form validation logic. |
|
1189 |
|
|
1190 |
``` php |
|
1191 |
<?php |
|
1192 |
$form = [ |
|
1193 |
'field1' => 'value', |
|
1194 |
'field2' => 'another value', |
|
1195 |
'checkbox1' => true, |
|
1196 |
// ... |
|
1197 |
]; |
|
1198 |
$I->submitForm('#my-form', $form, 'submitButton'); |
|
1199 |
// $I->amOnPage('/path/to/form-page') may be needed |
|
1200 |
$I->seeInFormFields('#my-form', $form); |
|
1201 |
``` |
|
1202 |
|
|
1203 |
Parameter values can be set to arrays for multiple input fields |
|
1204 |
of the same name, or multi-select combo boxes. For checkboxes, |
|
1205 |
you can use either the string value or boolean `true`/`false` which will |
|
1206 |
be replaced by the checkbox's value in the DOM. |
|
1207 |
|
|
1208 |
``` php |
|
1209 |
<?php |
|
1210 |
$I->submitForm('#my-form', [ |
|
1211 |
'field1' => 'value', |
|
1212 |
'checkbox' => [ |
|
1213 |
'value of first checkbox', |
|
1214 |
'value of second checkbox', |
|
1215 |
], |
|
1216 |
'otherCheckboxes' => [ |
|
1217 |
true, |
|
1218 |
false, |
|
1219 |
false |
|
1220 |
], |
|
1221 |
'multiselect' => [ |
|
1222 |
'first option value', |
|
1223 |
'second option value' |
|
1224 |
] |
|
1225 |
]); |
|
1226 |
``` |
|
1227 |
|
|
1228 |
Mixing string and boolean values for a checkbox's value is not supported |
|
1229 |
and may produce unexpected results. |
|
1230 |
|
|
1231 |
Field names ending in `[]` must be passed without the trailing square |
|
1232 |
bracket characters, and must contain an array for its value. This allows |
|
1233 |
submitting multiple values with the same name, consider: |
|
1234 |
|
|
1235 |
```php |
|
1236 |
<?php |
|
1237 |
// This will NOT work correctly |
|
1238 |
$I->submitForm('#my-form', [ |
|
1239 |
'field[]' => 'value', |
|
1240 |
'field[]' => 'another value', // 'field[]' is already a defined key |
|
1241 |
]); |
|
1242 |
``` |
|
1243 |
|
|
1244 |
The solution is to pass an array value: |
|
1245 |
|
|
1246 |
```php |
|
1247 |
<?php |
|
1248 |
// This way both values are submitted |
|
1249 |
$I->submitForm('#my-form', [ |
|
1250 |
'field' => [ |
|
1251 |
'value', |
|
1252 |
'another value', |
|
1253 |
] |
|
1254 |
]); |
|
1255 |
``` |
|
1256 |
|
|
1257 |
* `param` $selector |
|
1258 |
* `param` $params |
|
1259 |
* `param` $button |
|
1260 |
|
|
1261 |
|
|
1262 |
### switchToIframe |
|
1263 |
|
|
1264 |
Switch to iframe or frame on the page. |
|
1265 |
|
|
1266 |
Example: |
|
1267 |
``` html |
|
1268 |
<iframe name="another_frame" src="http://example.com"> |
|
1269 |
``` |
|
1270 |
|
|
1271 |
``` php |
|
1272 |
<?php |
|
1273 |
# switch to iframe |
|
1274 |
$I->switchToIframe("another_frame"); |
|
1275 |
``` |
|
1276 |
|
|
1277 |
* `param string` $name |
|
1278 |
|
|
1279 |
|
|
1280 |
### uncheckOption |
|
1281 |
|
|
1282 |
Unticks a checkbox. |
|
1283 |
|
|
1284 |
``` php |
|
1285 |
<?php |
|
1286 |
$I->uncheckOption('#notify'); |
|
1287 |
?> |
|
1288 |
``` |
|
1289 |
|
|
1290 |
* `param` $option |
|
1291 |
|
|
1292 |
<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/ZendExpressive.php">Help us to improve documentation. Edit module reference</a></div> |