| layout | doc |
|---|---|
| title | Symfony - Codeception - Documentation |
{% highlight yaml %} composer require --dev codeception/module-symfony
{% endhighlight %}
This module uses Symfony's DomCrawler and HttpKernel Component to emulate requests and test response.
- Access Symfony services through the dependency injection container:
$I->grabService(...) - Use Doctrine to test against the database:
$I->seeInRepository(...)- see Doctrine Module - Assert that emails would have been sent:
$I->seeEmailIsSent() - Tests are wrapped into Doctrine transaction to speed them up.
- Symfony Router can be cached between requests to speed up testing.
https://github.com/Codeception/symfony-module-tests
app_path: 'src' - Specify custom path to your app dir, where the kernel interface is located.environment: 'local' - Environment used for load kernelkernel_class: 'App\Kernel' - Kernel class nameem_service: 'doctrine.orm.entity_manager' - Use the stated EntityManager to pair with Doctrine Module.debug: true - Turn on/off debug modecache_router: 'false' - Enable router caching between tests in order to increase performance (can have an impact on ajax requests sending via '$I->sendAjaxPostRequest()')rebootable_client: 'true' - Reboot client's kernel before each requestguard: 'false' - Enable custom authentication system with guard (only for Symfony 5.4)bootstrap: 'false' - Enable the test environment setup with the tests/bootstrap.php file if it exists or with Symfony DotEnv otherwise. If false, it does nothing.authenticator: 'false' - Reboot client's kernel before each request (only for Symfony 6.0 or higher)
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'test'
- kernel - HttpKernel instance
- client - current Crawler instance
services: Includes methods related to the Symfony dependency injection container (DIC):- grabService
- persistService
- persistPermanentService
- unpersistService
See WebDriver module for general information on how to load parts of a framework module.
Usage example:
{% highlight yaml %}
actor: AcceptanceTester modules: enabled: - Symfony: part: services - Doctrine: depends: Symfony - WebDriver: url: http://example.com browser: firefox
{% endhighlight %}
If you're using Symfony with Eloquent ORM (instead of Doctrine), you can load the ORM part of Laravel module
in addition to Symfony module.
hidden API method, expected to be used from Helper classes
apiparam mixed$locatorreturn iterable
Locates element using available Codeception locator types:
- XPath
- CSS
- Strict Locator
Use it in Helpers or GroupObject or Extension classes:
{% highlight php %}
getModule('Symfony')->_findElements('.items'); $els = $this->getModule('Symfony')->_findElements(['name' => 'username']); $editLinks = $this->getModule('Symfony')->_findElements(['link' => 'Edit']); // now you can iterate over $editLinks and check that all them have valid hrefs {% endhighlight %} WebDriver module returns `Facebook\WebDriver\Remote\RemoteWebElement` instances PhpBrowser and Framework modules return `Symfony\Component\DomCrawler\Crawler` instances #### _getResponseContent *hidden API method, expected to be used from Helper classes* * `api` * `throws ModuleException` * `return string` Returns content of the last response Use it in Helpers when you want to retrieve response of request performed by another module. {% highlight php %} assertStringContainsString($text, $this->getModule('Symfony')->_getResponseContent(), "response contains"); } {% endhighlight %} #### _loadPage *hidden API method, expected to be used from Helper classes* * `api` * `param string` $method * `param string` $uri * `param array` $parameters * `param array` $files * `param array` $server * `param ?string` $content * `return void` Opens a page with arbitrary request parameters. Useful for testing multi-step forms on a specific step. {% highlight php %} getModule('Symfony')->_loadPage('POST', '/checkout/step2', ['order' => $orderId]); } {% endhighlight %} #### _request *hidden API method, expected to be used from Helper classes* * `api` * `see` `_loadPage` * `param string` $method * `param string` $uri * `param array` $parameters * `param array` $files * `param array` $server * `param ?string` $content * `throws ExternalUrlException|ModuleException` * `return ?string` Send custom request to a backend using method, uri, parameters, etc. Use it in Helpers to create special request actions, like accessing API Returns a string with response body. {% highlight php %} getModule('Symfony')->_request('POST', '/api/v1/users', ['name' => $name]); $user = json_decode($userData); return $user->id; } {% endhighlight %} Does not load the response into the module so you can't interact with response page (click, fill forms). To load arbitrary page for interaction, use `_loadPage` method. #### _savePageSource *hidden API method, expected to be used from Helper classes* * `api` * `param string` $filename * `return void` Saves page source of to a file {% highlight php %} $this->getModule('Symfony')->_savePageSource(codecept_output_dir().'page.html'); {% endhighlight %} #### amHttpAuthenticated * `param string` $username * `param string` $password * `return void` Authenticates user for HTTP_AUTH #### amLoggedInAs * `param \Symfony\Component\Security\Core\User\UserInterface` $user * `param string` $firewallName * `param ?string` $firewallContext * `return void` Login with the given user object. The `$user` object must have a persistent identifier. If you have more than one firewall or firewall context, you can specify the desired one as a parameter. {% highlight php %} grabEntityFromRepository(User::class, [ 'email' => 'john_doe@example.com' ]); $I->amLoggedInAs($user); {% endhighlight %} #### amLoggedInWithToken * `param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface` $token * `param string` $firewallName * `param ?string` $firewallContext * `return void` #### amOnAction * `param string` $action * `param array` $params * `return void` Opens web page by action name {% highlight php %} amOnAction('PostController::index'); $I->amOnAction('HomeController'); $I->amOnAction('ArticleController', ['slug' => 'lorem-ipsum']); {% endhighlight %} #### amOnPage * `param string` $page * `return void` Opens the page for the given relative URI. {% highlight php %} amOnPage('/'); // opens /register page $I->amOnPage('/register'); {% endhighlight %} #### amOnRoute * `param string` $routeName * `param array` $params * `return void` Opens web page using route name and parameters. {% highlight php %} amOnRoute('posts.create'); $I->amOnRoute('posts.show', ['id' => 34]); {% endhighlight %} #### assertBrowserCookieValueSame * `param string` $name * `param string` $expectedValue * `param bool` $raw * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the given cookie in the test client is set to the expected value. {% highlight php %} assertBrowserCookieValueSame('cookie_name', 'expected_value'); {% endhighlight %} #### assertBrowserHasCookie * `param string` $name * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the test client has the specified cookie set. This indicates that the cookie was set by any response during the test. {% highlight yaml %} assertBrowserHasCookie('cookie_name'); {% endhighlight %} #### assertBrowserNotHasCookie * `param string` $name * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the test client does not have the specified cookie set. This indicates that the cookie was not set by any response during the test. {% highlight php %} assertBrowserNotHasCookie('cookie_name'); {% endhighlight %} #### assertCheckboxChecked * `param string` $fieldName * `param string` $message * `return void` Asserts that the checkbox with the given name is checked. {% highlight php %} assertCheckboxChecked('agree_terms'); {% endhighlight %} #### assertCheckboxNotChecked * `param string` $fieldName * `param string` $message * `return void` Asserts that the checkbox with the given name is not checked. {% highlight php %} assertCheckboxNotChecked('subscribe'); {% endhighlight %} #### assertEmailAddressContains * `param string` $headerName * `param string` $expectedValue * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that an email contains addresses with a [header](https://datatracker.ietf.org/doc/html/rfc4021) `$headerName` and its expected value `$expectedValue`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailAddressContains('To', 'jane_doe@example.com'); {% endhighlight %} #### assertEmailAttachmentCount * `param int` $count * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that an email has sent the specified number `$count` of attachments. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailAttachmentCount(1); {% endhighlight %} #### assertEmailCount * `param int` $count * `param ?string` $transport * `param string` $message * `return void` Asserts that the expected number of emails was sent. {% highlight php %} assertEmailCount(2, 'smtp'); {% endhighlight %} #### assertEmailHasHeader * `param string` $headerName * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that an email has a [header](https://datatracker.ietf.org/doc/html/rfc4021) `$headerName`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailHasHeader('Bcc'); {% endhighlight %} #### assertEmailHeaderNotSame * `param string` $headerName * `param string` $expectedValue * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that the [header](https://datatracker.ietf.org/doc/html/rfc4021) `$headerName` of an email is not the expected one `$expectedValue`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailHeaderNotSame('To', 'john_doe@gmail.com'); {% endhighlight %} #### assertEmailHeaderSame * `param string` $headerName * `param string` $expectedValue * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that the [header](https://datatracker.ietf.org/doc/html/rfc4021) `$headerName` of an email is the same as expected `$expectedValue`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailHeaderSame('To', 'jane_doe@gmail.com'); {% endhighlight %} #### assertEmailHtmlBodyContains * `param string` $text * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that the HTML body of an email contains `$text`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailHtmlBodyContains('Successful registration'); {% endhighlight %} #### assertEmailHtmlBodyNotContains * `param string` $text * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that the HTML body of an email does not contain a text `$text`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailHtmlBodyNotContains('userpassword'); {% endhighlight %} #### assertEmailIsNotQueued * `param \Symfony\Component\Mailer\Event\MessageEvent` $event * `param string` $message * `return void` Asserts that the given mailer event is not queued. Use `getMailerEvent(int $index = 0, ?string $transport = null)` to retrieve a mailer event by index. {% highlight php %} getMailerEvent(); $I->assertEmailIsNotQueued($event); {% endhighlight %} #### assertEmailIsQueued * `param \Symfony\Component\Mailer\Event\MessageEvent` $event * `param string` $message * `return void` Asserts that the given mailer event is queued. Use `getMailerEvent(int $index = 0, ?string $transport = null)` to retrieve a mailer event by index. {% highlight php %} getMailerEvent(); $I->assertEmailIsQueued($event); {% endhighlight %} #### assertEmailNotHasHeader * `param string` $headerName * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that an email does not have a [header](https://datatracker.ietf.org/doc/html/rfc4021) `$headerName`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailNotHasHeader('Bcc'); {% endhighlight %} #### assertEmailTextBodyContains * `param string` $text * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify the text body of an email contains a `$text`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailTextBodyContains('Example text body'); {% endhighlight %} #### assertEmailTextBodyNotContains * `param string` $text * `param ?\Symfony\Component\Mime\Email` $email * `return void` Verify that the text body of an email does not contain a `$text`. If the Email object is not specified, the last email sent is used instead. {% highlight php %} assertEmailTextBodyNotContains('My secret text body'); {% endhighlight %} #### assertFormValue * `param string` $formSelector * `param string` $fieldName * `param string` $value * `param string` $message * `return void` Asserts that value of the field of the first form matching the given selector does equal the expected value. {% highlight php %} assertFormValue('#loginForm', 'username', 'john_doe'); {% endhighlight %} #### assertHttpClientRequest * `param string` $expectedUrl * `param string` $expectedMethod * `param string|array|null` $expectedBody * `param array` $expectedHeaders * `param string` $httpClientId * `return void` Asserts that the given URL has been called using, if specified, the given method, body and/or headers. By default, it will inspect the default Symfony HttpClient; you may check a different one by passing its service-id in $httpClientId. It succeeds even if the request was executed multiple times. {% highlight php %} assertHttpClientRequest( 'https://example.com/api', 'POST', '{"data": "value"}', ['Authorization' => 'Bearer token'] ); {% endhighlight %} #### assertHttpClientRequestCount * `param int` $count * `param string` $httpClientId * `return void` Asserts that exactly $count requests have been executed by the given HttpClient. By default, it will inspect the default Symfony HttpClient; you may check a different one by passing its service-id in $httpClientId. {% highlight php %} $I->assertHttpClientRequestCount(3); {% endhighlight %} #### assertInputValueNotSame * `param string` $fieldName * `param string` $expectedValue * `param string` $message * `return void` Asserts that the value of the form input with the given name does not equal the expected value. {% highlight php %} assertInputValueNotSame('username', 'admin'); {% endhighlight %} #### assertInputValueSame * `param string` $fieldName * `param string` $expectedValue * `param string` $message * `return void` Asserts that the value of the form input with the given name equals the expected value. {% highlight php %} assertInputValueSame('username', 'johndoe'); {% endhighlight %} #### assertNoFormValue * `param string` $formSelector * `param string` $fieldName * `param string` $message * `return void` Asserts that the field of the first form matching the given selector does not have a value. {% highlight php %} assertNoFormValue('#registrationForm', 'middle_name'); {% endhighlight %} #### assertNotHttpClientRequest * `param string` $unexpectedUrl * `param string` $unexpectedMethod * `param string` $httpClientId * `return void` Asserts that the given URL *has not* been requested with the supplied HTTP method. By default, it will inspect the default Symfony HttpClient; you may check a different one by passing its service-id in $httpClientId. {% highlight php %} $I->assertNotHttpClientRequest('https://example.com/unexpected', 'GET'); {% endhighlight %} #### assertNotificationCount * `param int` $count * `param ?string` $transportName * `param string` $message * `return void` Asserts that the expected number of notifications was sent. {% highlight php %} assertNotificationCount(2, 'smtp'); {% endhighlight %} #### assertNotificationIsNotQueued * `param \Symfony\Component\Notifier\Event\MessageEvent` $event * `param string` $message * `return void` Asserts that the given notifier event is not queued. Use `getNotifierEvent(int $index = 0, ?string $transportName = null)` to retrieve a notifier event by index. {% highlight php %} getNotifierEvent(); $I->asserNotificationIsNotQueued($event); {% endhighlight %} #### assertNotificationIsQueued * `param \Symfony\Component\Notifier\Event\MessageEvent` $event * `param string` $message * `return void` Asserts that the given notifier event is queued. Use `getNotifierEvent(int $index = 0, ?string $transportName = null)` to retrieve a notifier event by index. {% highlight php %} getNotifierEvent(); $I->assertNotificationIsQueued($event); {% endhighlight %} #### assertNotificationSubjectContains * `param \Symfony\Component\Notifier\Message\MessageInterface` $notification * `param string` $text * `param string` $message * `return void` Asserts that the given notification contains given subject. Use `getNotifierMessage(int $index = 0, ?string $transportName = null)` to retrieve a notification by index. {% highlight php %} getNotifierMessage(); $I->assertNotificationSubjectContains($notification, 'Subject'); {% endhighlight %} #### assertNotificationSubjectNotContains * `param \Symfony\Component\Notifier\Message\MessageInterface` $notification * `param string` $text * `param string` $message * `return void` Asserts that the given notification does not contain given subject. Use `getNotifierMessage(int $index = 0, ?string $transportName = null)` to retrieve a notification by index. {% highlight php %} getNotifierMessage(); $I->assertNotificationSubjectNotContains($notification, 'Subject'); {% endhighlight %} #### assertNotificationTransportIsEqual * `param \Symfony\Component\Notifier\Message\MessageInterface` $notification * `param ?string` $transportName * `param string` $message * `return void` Asserts that the given notification uses given transport. Use `getNotifierMessage(int $index = 0, ?string $transportName = null)` to retrieve a notification by index. {% highlight php %} getNotifierMessage(); $I->assertNotificationTransportIsEqual($notification, 'chat'); {% endhighlight %} #### assertNotificationTransportIsNotEqual * `param \Symfony\Component\Notifier\Message\MessageInterface` $notification * `param ?string` $transportName * `param string` $message * `return void` Asserts that the given notification does not use given transport. Use `getNotifierMessage(int $index = 0, ?string $transportName = null)` to retrieve a notification by index. {% highlight php %} getNotifierMessage(); $I->assertNotificationTransportIsNotEqual($notification, 'transport'); {% endhighlight %} #### assertPageTitleContains * `param string` $expectedTitle * `param string` $message * `return void` Asserts that the `<title>` element contains the given title. {% highlight php %} assertPageTitleContains('Welcome'); {% endhighlight %} #### assertPageTitleSame * `param string` $expectedTitle * `param string` $message * `return void` Asserts that the `<title>` element equals the given title. {% highlight php %} assertPageTitleSame('Home Page'); {% endhighlight %} #### assertQueuedEmailCount * `param int` $count * `param ?string` $transport * `param string` $message * `return void` Asserts that the expected number of emails was queued (e.g. using the Messenger component). {% highlight php %} assertQueuedEmailCount(1, 'smtp'); {% endhighlight %} #### assertQueuedNotificationCount * `param int` $count * `param ?string` $transportName * `param string` $message * `return void` Asserts that the expected number of notifications was queued (e.g. using the Notifier component). {% highlight php %} assertQueuedNotificationCount(1, 'smtp'); {% endhighlight %} #### assertRequestAttributeValueSame * `param string` $name * `param string` $expectedValue * `param string` $message * `return void` Asserts that the specified request attribute matches the expected value. {% highlight php %} assertRequestAttributeValueSame('attribute_name', 'expected_value'); {% endhighlight %} #### assertResponseCookieValueSame * `param string` $name * `param string` $expectedValue * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the specified response cookie is present and matches the expected value. {% highlight php %} assertResponseCookieValueSame('cookie_name', 'expected_value'); {% endhighlight %} #### assertResponseFormatSame * `param ?string` $expectedFormat * `param string` $message * `return void` Asserts that the response format matches the expected format. This checks the format returned by the `Response::getFormat()` method. {% highlight php %} assertResponseFormatSame('json'); {% endhighlight %} #### assertResponseHasCookie * `param string` $name * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the specified cookie is present in the response. Optionally, it can check for a specific cookie path or domain. {% highlight php %} assertResponseHasCookie('cookie_name'); {% endhighlight %} #### assertResponseHasHeader * `param string` $headerName * `param string` $message * `return void` Asserts that the specified header is available in the response. For example, use `assertResponseHasHeader('content-type');`. {% highlight php %} assertResponseHasHeader('content-type'); {% endhighlight %} #### assertResponseHeaderNotSame * `param string` $headerName * `param string` $expectedValue * `param string` $message * `return void` Asserts that the specified header does not contain the expected value in the response. For example, use `assertResponseHeaderNotSame('content-type', 'application/octet-stream');`. {% highlight php %} assertResponseHeaderNotSame('content-type', 'application/json'); {% endhighlight %} #### assertResponseHeaderSame * `param string` $headerName * `param string` $expectedValue * `param string` $message * `return void` Asserts that the specified header contains the expected value in the response. For example, use `assertResponseHeaderSame('content-type', 'application/octet-stream');`. {% highlight php %} assertResponseHeaderSame('content-type', 'application/json'); {% endhighlight %} #### assertResponseIsSuccessful * `param string` $message * `param bool` $verbose * `return void` Asserts that the response was successful (HTTP status code is in the 2xx range). {% highlight php %} assertResponseIsSuccessful(); {% endhighlight %} #### assertResponseIsUnprocessable * `param string` $message * `param bool` $verbose * `return void` Asserts that the response is unprocessable (HTTP status code is 422). {% highlight php %} assertResponseIsUnprocessable(); {% endhighlight %} #### assertResponseNotHasCookie * `param string` $name * `param string` $path * `param ?string` $domain * `param string` $message * `return void` Asserts that the specified cookie is not present in the response. Optionally, it can check for a specific cookie path or domain. {% highlight php %} assertResponseNotHasCookie('cookie_name'); {% endhighlight %} #### assertResponseNotHasHeader * `param string` $headerName * `param string` $message * `return void` Asserts that the specified header is not available in the response. {% highlight php %} assertResponseNotHasHeader('content-type'); {% endhighlight %} #### assertResponseRedirects * `param ?string` $expectedLocation * `param ?int` $expectedCode * `param string` $message * `param bool` $verbose * `return void` Asserts that the response is a redirect. Optionally, you can check the target location and status code. The expected location can be either an absolute or a relative path. {% highlight php %} assertResponseRedirects('/login', 302); {% endhighlight %} #### assertResponseStatusCodeSame * `param int` $expectedCode * `param string` $message * `param bool` $verbose * `return void` Asserts that the response status code matches the expected code. {% highlight php %} assertResponseStatusCodeSame(200); {% endhighlight %} #### assertRouteSame * `param string` $expectedRoute * `param array` $parameters * `param string` $message * `return void` Asserts the request matches the given route and optionally route parameters. {% highlight php %} assertRouteSame('profile', ['id' => 123]); {% endhighlight %} #### assertSelectorExists * `param string` $selector * `param string` $message * `return void` Asserts that the given selector matches at least one element in the response. {% highlight php %} assertSelectorExists('.main-content'); {% endhighlight %} #### assertSelectorNotExists * `param string` $selector * `param string` $message * `return void` Asserts that the given selector does not match at least one element in the response. {% highlight php %} assertSelectorNotExists('.error'); {% endhighlight %} #### assertSelectorTextContains * `param string` $selector * `param string` $text * `param string` $message * `return void` Asserts that the first element matching the given selector contains the expected text. {% highlight php %} assertSelectorTextContains('h1', 'Dashboard'); {% endhighlight %} #### assertSelectorTextNotContains * `param string` $selector * `param string` $text * `param string` $message * `return void` Asserts that the first element matching the given selector does not contain the expected text. {% highlight php %} assertSelectorTextNotContains('p', 'error'); {% endhighlight %} #### assertSelectorTextSame * `param string` $selector * `param string` $text * `param string` $message * `return void` Asserts that the text of the first element matching the given selector equals the expected text. {% highlight php %} assertSelectorTextSame('h1', 'Dashboard'); {% endhighlight %} #### attachFile * `param ` $field * `param string` $filename * `return void` Attaches a file relative to the Codeception `_data` directory to the given file upload field. {% highlight php %} attachFile('input[@type="file"]', 'prices.xls'); {% endhighlight %} #### checkOption * `param ` $option * `return void` Ticks a checkbox. For radio buttons, use the `selectOption` method instead. {% highlight php %} checkOption('#agree'); {% endhighlight %} #### click * `param string|array` $link * `param ` $context * `return void` Perform a click on a link or a button, given by a locator. If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched. For images, the "alt" attribute and inner text of any parent links are searched. The second parameter is a context (CSS or XPath locator) to narrow the search. Note that if the locator matches a button of type `submit`, the form will be submitted. {% highlight php %} click('Logout'); // button of form $I->click('Submit'); // CSS button $I->click('#form input[type=submit]'); // XPath $I->click('//form/*[@type="submit"]'); // link in context $I->click('Logout', '#nav'); // using strict locator $I->click(['link' => 'Login']); {% endhighlight %} #### deleteHeader @deprecated * `param string` $name * `return void` #### dontSee * `param string` $text * `param array|string` $selector optional * `return void` Checks that the current page doesn't contain the text specified (case insensitive). Give a locator as the second parameter to match a specific region. {% highlight php %} dontSee('Login'); // I can suppose user is already logged in $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page $I->dontSee('Sign Up','//body/h1'); // with XPath $I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator {% endhighlight %} Note that the search is done after stripping all HTML tags from the body, so `$I->dontSee('strong')` will fail on strings like: - `I am Stronger than thou
` - `<script>document.createElement('strong');</script>` But will ignore strings like: - `Home` - `I am Stronger than thou
` - `<script>document.createElement('strong');</script>` But will *not* be true for strings like: - `Home` - `Password:
Do you agree to our terms?
Subscribe to our newsletter?
Select pricing plan: Free Paid {% endhighlight %} You could write the following to submit it: {% highlight php %} submitForm( '#userForm', [ 'user' => [ 'login' => 'Davert', 'password' => '123456', 'agree' => true ] ], 'submitButton' ); {% endhighlight %} Note that "2" will be the submitted value for the "plan" field, as it is the selected option. To uncheck the pre-checked checkbox "newsletter", call `$I->uncheckOption(['name' => 'user[newsletter]']);` *before*, then submit the form as shown here (i.e. without the "newsletter" field in the `$params` array). You can also emulate a JavaScript submission by not specifying any buttons in the third parameter to submitForm. {% highlight php %} submitForm( '#userForm', [ 'user' => [ 'login' => 'Davert', 'password' => '123456', 'agree' => true ] ] ); {% endhighlight %} This function works well when paired with `seeInFormFields()` for quickly testing CRUD interfaces and form validation logic. {% highlight php %} 'value', 'field2' => 'another value', 'checkbox1' => true, // ... ]; $I->submitForm('#my-form', $form, 'submitButton'); // $I->amOnPage('/path/to/form-page') may be needed $I->seeInFormFields('#my-form', $form); {% endhighlight %} Parameter values can be set to arrays for multiple input fields of the same name, or multi-select combo boxes. For checkboxes, you can use either the string value or boolean `true`/`false` which will be replaced by the checkbox's value in the DOM. {% highlight php %} submitForm('#my-form', [ 'field1' => 'value', 'checkbox' => [ 'value of first checkbox', 'value of second checkbox', ], 'otherCheckboxes' => [ true, false, false ], 'multiselect' => [ 'first option value', 'second option value' ] ]); {% endhighlight %} Mixing string and boolean values for a checkbox's value is not supported and may produce unexpected results. Field names ending in `[]` must be passed without the trailing square bracket characters, and must contain an array for its value. This allows submitting multiple values with the same name, consider: {% highlight php %} submitForm('#my-form', [ 'field[]' => 'value', 'field[]' => 'another value', // 'field[]' is already a defined key ]); {% endhighlight %} The solution is to pass an array value: {% highlight php %} submitForm('#my-form', [ 'field' => [ 'value', 'another value', ] ]); {% endhighlight %} #### submitSymfonyForm * `param string` $name The `name` attribute of the ``. You cannot use an array as a selector here. * `param array` $fields * `return void` Submits a form by specifying the form name only once. Use this function instead of [`$I->submitForm()`](#submitForm) to avoid repeating the form name in the field selectors. If you have customized the names of the field selectors, use `$I->submitForm()` for full control. {% highlight php %} submitSymfonyForm('login_form', [ '[email]' => 'john_doe@example.com', '[password]' => 'secretForest' ]); {% endhighlight %} #### switchToIframe * `param string` $name * `return void` Switch to iframe or frame on the page. Example: {% highlight html %} <iframe name="another_frame" src="http://example.com"> {% endhighlight %} {% highlight php %} switchToIframe("another_frame"); {% endhighlight %} #### uncheckOption * `param ` $option * `return void` Unticks a checkbox. {% highlight php %} uncheckOption('#notify'); {% endhighlight %} #### unpersistService * `part` services * `param non-empty-string` $serviceName * `return void` Remove service $serviceName from the lists of persistent services. #### unsetHttpHeader * `param string` $name the name of the header to unset. * `return void` Unsets a HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)), so that subsequent requests will not send it anymore. Example: {% highlight php %} haveHttpHeader('X-Requested-With', 'Codeception'); $I->amOnPage('test-headers.php'); // ... $I->unsetHeader('X-Requested-With'); $I->amOnPage('some-other-page.php'); {% endhighlight %}