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