Testomatio - Test Management for Codeception
This module allows you to run functional tests for Laravel 6.0+ It should not be used for acceptance tests. See the Acceptance tests section below for more details.
https://github.com/Codeception/laravel-module-tests
boolean
, default true
- all database queries will be run in a transaction,
which will be rolled back at the end of each test.boolean
, default false
- run database migrations before each test.string
, default null
- path to the database migrations, relative to the root of the application.boolean
, default false
- run database seeder before each test.string
, default `` - database seeder class name.string
, default .env
- the environment file to load for the tests.string
, default bootstrap/app.php
- relative path to app.php config file.string
, default `` - root path of the application.string
, default workbench
- root path of application packages (if any).string
, default vendor
- optional relative path to vendor directory.boolean
, default true
- disable Laravel exception handling.boolean
, default false
- disable all middleware.boolean
, default false
- disable events (does not disable model events).boolean
, default false
- disable model events.string
, default `` - the application URL.array<string, string>
- default headers are set before each test.functional.suite.yml
)Enabling module:
functional.suite.yml
)Enabling module with custom .env file
Illuminate\Foundation\Application
array
ORM
: Only include the database methods of this module:
See WebDriver module for general information on how to load parts of a framework module.
You should not use this module for acceptance tests. If you want to use Eloquent within your acceptance tests (paired with WebDriver) enable only ORM part of this module:
acceptance.suite.yml
)hidden API method, expected to be used from Helper classes
api
param mixed
$locatorreturn iterable
Locates element using available Codeception locator types:
Use it in Helpers or GroupObject or Extension classes:
WebDriver module returns Facebook\WebDriver\Remote\RemoteWebElement
instances
PhpBrowser and Framework modules return Symfony\Component\DomCrawler\Crawler
instances
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.
hidden API method, expected to be used from Helper classes
api
param string
$methodparam string
$uriparam array
$parametersparam array
$filesparam array
$serverparam ?string
$contentreturn void
Opens a page with arbitrary request parameters.
Useful for testing multi-step forms on a specific step.
hidden API method, expected to be used from Helper classes
api
see
_loadPage
param string
$methodparam string
$uriparam array
$parametersparam array
$filesparam array
$serverparam ?string
$contentthrows 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.
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.
hidden API method, expected to be used from Helper classes
api
param string
$filenamereturn void
Saves page source of to a file
param \Illuminate\Contracts\Auth\Authenticatable
$userparam ?string
$guardNamereturn void
Set the given user object to the current or specified Guard.
param string
$usernameparam string
$passwordreturn void
Authenticates user for HTTP_AUTH
param Authenticatable|array
$userparam string|null
$guardNamereturn void
Set the currently logged in user for the application.
Unlike âamActingAsâ, this method does update the session, fire the login events and remember the user as it assigns the corresponding Cookie.
param string
$actionparam mixed
$parametersreturn void
Opens web page by action name
param string
$pagereturn void
Opens the page for the given relative URI.
param string
$routeNameparam mixed
$paramsreturn void
Opens web page using route name and parameters.
param \Illuminate\Contracts\Auth\Authenticatable
$userparam ?string
$guardNamereturn void
Assert that the user is authenticated as the given user.
param array
$credentialsparam ?string
$guardNamereturn void
Assert that the given credentials are valid.
param array
$credentialsparam ?string
$guardNamereturn void
Assert that the given credentials are invalid.
param
$fieldparam string
$filenamereturn void
Attaches a file relative to the Codeception _data
directory to the given file upload field.
param string
$commandparam array
$parametersparam ?\Symfony\Component\Console\Output\OutputInterface
$outputreturn string|void
Call an Artisan command.
Use 3rd parameter to pass in custom OutputInterface
param
$optionreturn void
Ticks a checkbox. For radio buttons, use the selectOption
method instead.
return void
Clear the registered application handlers.
param string|array
$linkparam
$contextreturn 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.
@deprecated
param string
$namereturn void
return void
Disable events for the next requests.
This method does not disable model events. To disable model events you have to use the disableModelEvents() method.
return void
Disable Laravel exception handling.
param string|array|null
$middlewarereturn void
Disable middleware for the next requests.
return void
Disable model events for the next requests.
param string
$textparam array|string
$selector optionalreturn 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.
Note that the search is done after stripping all HTML tags from the body,
so $I->dontSee('strong')
will fail on strings like:
<p>I am Stronger than thou</p>
<script>document.createElement('strong');</script>
But will ignore strings like:
<strong>Home</strong>
<div class="strong">Home</strong>
<!-- strong -->
For checking the raw source code, use seeInSource()
.
param ?string
$guardNamereturn void
Check that user is not authenticated.
param
$checkboxreturn void
Check that the specified checkbox is unchecked.
param
$cookieparam
$paramsreturn mixed|void
Checks that there isnât a cookie with the given name.
You can set additional cookie params like domain
, path
as array passed in last argument.
param string
$urireturn void
Checks that the current URL doesnât equal the given string.
Unlike dontSeeInCurrentUrl
, this only matches the full URL.
param string
$urireturn void
Checks that current url doesnât match the given regular expression.
param
$selectorparam array
$attributesreturn void
Checks that the given element is invisible or not present on the page.
You can also specify expected attributes of this element.
param string|object|string[]
$expectedreturn void
Make sure events did not fire during the test.
return void
Assert that there are no form errors bound to the View.
param string
$urireturn void
Checks that the current URI doesnât contain the given string.
param string|array
$fieldparam
$valuereturn void
Checks that an input field or textarea doesnât contain the given value.
For fuzzy locators, the field is matched by label text, CSS and XPath.
param
$formSelectorparam array
$paramsreturn void
Checks if the array of form parameters (name => value) are not set on the form matched with the passed selector.
To check that an element hasnât been assigned any one of many values, an array can be passed as the value:
Additionally, checkbox values can be checked with a boolean.
param string|array
$keyparam mixed|null
$valuereturn void
Assert that a session attribute does not exist, or is not equal to the passed value.
param string
$rawreturn void
Checks that the current page contains the given string in its raw source code.
param
$titlereturn mixed|void
Checks that the page title does not contain the given string.
param string
$textparam string
$urlreturn void
Checks that the page doesnât contain a link with the given string.
If the second parameter is given, only links with a matching âhrefâ attribute will be checked.
param
$selectorparam
$optionTextreturn mixed|void
Checks that the given option is not selected.
part
ormparam string|class-string|object
$tableparam array
$attributesreturn void
Checks that record does not exist in database.
You can pass the name of a database table or the class name of an Eloquent model as the first argument.
param int
$codereturn void
Checks that response code is equal to value provided.
param array
$bindingsreturn void
Assert that the session does not have a particular list of values.
return void
Enable Laravel exception handling.
param string|array|null
$middlewarereturn void
Enable the given middleware for the next requests.
param
$fieldparam
$valuereturn void
Fills a text field or textarea with the given string.
return void
Flush all of the current session data.
return void
Follow pending redirect if there is one.
return \Illuminate\Contracts\Foundation\Application
Provides access the Laravel application object.
param
$cssOrXpathparam string
$attributereturn mixed
Returns the value of the given attribute value from the given HTML element. For some attributes, the string true
is returned instead of their literal value (e.g. disabled="disabled"
or required="required"
).
Fails if the element is not found. Returns null
if the attribute is not present on the element.
param string
$cookieparam array
$paramsreturn mixed
Grabs a cookie value.
You can set additional cookie params like domain
, path
in array passed as last argument.
If the cookie is set by an ajax request (XMLHttpRequest), there might be some delay caused by the browser, so try $I->wait(0.1)
.
param ?string
$urireturn mixed
Executes the given regular expression against the current URI and returns the first capturing group.
If no parameters are provided, the full URI is returned.
param
$cssOrXpathparam ?string
$attributereturn string[]
Grabs either the text content, or attribute values, of nodes matched by $cssOrXpath and returns them as an array.
part
ormparam string
$tableparam array
$attributesreturn int
Retrieves number of records from database You can pass the name of a database table or the class name of an Eloquent model as the first argument.
throws \Codeception\Exception\ModuleException
if no page was opened.return string
Current page source code.Grabs current page source code.
part
ormparam string
$tableparam array
$attributesreturn array|EloquentModel
Retrieves record from database If you pass the name of a database table as the first argument, this method returns an array.
You can also pass the class name of an Eloquent model, in that case this method returns an Eloquent model.
param string
$classreturn mixed
Return an instance of a class from the Laravel service container.
(https://laravel.com/docs/7.x/container)
param
$cssOrXPathOrRegexreturn mixed
Finds and returns the text contents of the given element.
If a fuzzy locator is used, the element is found using CSS, XPath, and by matching the full page source by regular expression.
param
$fieldreturn mixed
Finds the value for the given form field.
If a fuzzy locator is used, the field is found by field name, CSS, and XPath.
part
ormsee
https://laravel.com/docs/7.x/database-testing#using-factoriesparam string
$modelparam array
$attributesparam string
$namereturn mixed
Use Laravel model factory to create a model.
param callable
$handlerreturn void
Register a handler than can be used to modify the Laravel application object after it is initialized.
The Laravel application object will be passed as an argument to the handler.
param string
$abstractparam Closure|string|null
$concreteparam bool
$sharedreturn void
Add a binding to the Laravel service container.
(https://laravel.com/docs/7.x/container)
param string
$concreteparam string
$abstractparam Closure|string
$implementationreturn void
Add a contextual binding to the Laravel service container.
(https://laravel.com/docs/7.x/container)
param string
$name the name of the request headerparam string
$value the value to set it to for subsequent
requestsreturn void
Sets the HTTP header to the passed value - which is used on subsequent HTTP requests through PhpBrowser.
Example:
To use special chars in Header Key use HTML Character Entities: Example: Header with underscore - âClient_Idâ should be represented as - âClient_Idâ or âClient_Idâ
param array
$datareturn void
Set the session to the given array.
param string
$abstractparam object
$instancereturn void
Add an instance binding to the Laravel service container.
(https://laravel.com/docs/7.x/container)
part
ormsee
https://laravel.com/docs/7.x/database-testing#using-factoriesparam string
$modelparam int
$timesparam array
$attributesparam string
$namereturn EloquentModel|EloquentCollection
Use Laravel model factory to create multiple models.
part
ormparam string
$tableparam array
$attributesthrows RuntimeException
return EloquentModel|int
Inserts record into the database.
If you pass the name of a database table as the first argument, this method returns an integer ID. You can also pass the class name of an Eloquent model, in that case this method returns an Eloquent model.
param string
$nameparam string
$valuereturn void
Sets SERVER parameter valid for all next requests.
param string
$abstractparam Closure|string|null
$concretereturn void
Add a singleton binding to the Laravel service container.
(https://laravel.com/docs/7.x/container)
return void
Logout user.
part
ormsee
https://laravel.com/docs/7.x/database-testing#using-factoriesparam string
$modelparam array
$attributesparam string
$namereturn EloquentCollection|EloquentModel
Use Laravel model factory to make a model instance.
param ?string
$namereturn void
Use this method within an interactive pause to save the HTML source code of the current page.
part
ormsee
https://laravel.com/docs/7.x/database-testing#using-factoriesparam string
$modelparam int
$timesparam array
$attributesparam string
$namereturn EloquentCollection|EloquentModel
Use Laravel model factory to make multiple model instances.
param int
$numberOfSteps (default value 1)return void
Moves back in history.
param
$cookieparam
$paramsreturn mixed|void
Unsets cookie with the given name.
You can set additional cookie params like domain
, path
in array passed as last argument.
param string
$textparam array|string
$selector optionalreturn void
Checks that the current page contains the given string (case insensitive).
You can specify a specific HTML element (via CSS or XPath) as the second parameter to only search within that element.
Note that the search is done after stripping all HTML tags from the body,
so $I->see('strong')
will return true for strings like:
<p>I am Stronger than thou</p>
<script>document.createElement('strong');</script>
But will not be true for strings like:
<strong>Home</strong>
<div class="strong">Home</strong>
<!-- strong -->
For checking the raw source code, use seeInSource()
.
param ?string
$guardNamereturn void
Checks that a user is authenticated.
param
$checkboxreturn void
Checks that the specified checkbox is checked.
param
$cookieparam
$paramsreturn mixed|void
Checks that a cookie with the given name is set.
You can set additional cookie params like domain
, path
as array passed in last argument.
param string
$actionreturn void
Checks that current url matches action
param string
$routeNamereturn void
Checks that current url matches route
param string
$urireturn void
Checks that the current URL is equal to the given string.
Unlike seeInCurrentUrl
, this only matches the full URL.
param string
$urireturn void
Checks that the current URL matches the given regular expression.
param
$selectorparam array
$attributesreturn void
Checks that the given element exists on the page and is visible.
You can also specify expected attributes of this element.
Only works if <html>
tag is present.
param string|object|string[]
$expectedreturn void
Make sure events fired during the test.
param string
$fieldparam ?string
$errorMessagereturn void
Assert that a specific form error message is set in the view.
If you want to assert that there is a form error message for a specific key
but donât care about the actual error message you can omit $expectedErrorMessage
.
If you do pass $expectedErrorMessage
, this method checks if the actual error message for a key
contains $expectedErrorMessage
.
param array
$expectedErrorsreturn void
Verifies that multiple fields on a form have errors.
This method will validate that the expected error message is contained in the actual error message, that is, you can specify either the entire error message or just a part of it:
If you donât want to specify the error message for some fields,
you can pass null
as value instead of the message string.
If that is the case, it will be validated that
that field has at least one error of any type:
return void
Assert that form errors are bound to the View.
param string
$urireturn void
Checks that current URI contains the given string.
param string|array
$fieldparam
$valuereturn void
Checks that the given input field or textarea equals (i.e. not just contains) the given value.
Fields are matched by label text, the ânameâ attribute, CSS, or XPath.
param
$formSelectorparam array
$paramsreturn void
Checks if the array of form parameters (name => value) are set on the form matched with the passed selector.
For multi-select elements, or to check values of multiple elements with the same name, an array may be passed:
Additionally, checkbox values can be checked with a boolean.
Pair this with submitForm for quick testing magic.
param string|array
$keyparam mixed|null
$valuereturn void
Assert that a session variable exists.
param string
$rawreturn void
Checks that the current page contains the given string in its raw source code.
param
$titlereturn mixed|void
Checks that the page title contains the given string.
param string
$textparam ?string
$urlreturn void
Checks that thereâs a link with the specified text.
Give a full URL as the second parameter to match links with that exact URL.
part
ormparam int
$expectedNumparam string
$tableparam array
$attributesreturn void
Checks that number of given records were found in database.
You can pass the name of a database table or the class name of an Eloquent model as the first argument.
param
$selectorparam int|int[]
$expectedreturn void
Checks that there are a certain number of elements matched by the given locator on the page.
param
$selectorparam
$optionTextreturn mixed|void
Checks that the given option is selected.
return void
Asserts that current page has 404 response status code.
part
ormparam string|class-string|object
$tableparam array
$attributesreturn void
Checks that record exists in database.
You can pass the name of a database table or the class name of an Eloquent model as the first argument.
param int
$codereturn void
Checks that response code is equal to value provided.
param int
$fromparam int
$toreturn void
Checks that response code is between a certain range. Between actually means [from <= CODE <= to]
return void
Checks that the response code is 4xx
return void
Checks that the response code 3xx
return void
Checks that the response code is 5xx
return void
Checks that the response code 2xx
param array
$bindingsreturn void
Assert that the session has a given list of values.
param class-string|class-string[]
$seedersreturn void
Seed a given database connection.
param
$selectparam
$optionreturn void
Selects an option in a select tag or in radio button group.
Provide an array for the second argument to select multiple options:
Or provide an associative array for the second argument to specifically define which selection method should be used:
param string
$uriparam array
$paramsreturn void
Sends an ajax GET request with the passed parameters.
See sendAjaxPostRequest()
param string
$uriparam array
$paramsreturn void
Sends an ajax POST request with the passed parameters.
The appropriate HTTP header is added automatically:
X-Requested-With: XMLHttpRequest
Example:
Some frameworks (e.g. Symfony) create field names in the form of an âarrayâ:
<input type="text" name="form[task]">
In this case you need to pass the fields like this:
param string
$methodparam string
$uriparam array
$paramsreturn void
Sends an ajax request, using the passed HTTP method.
See sendAjaxPostRequest()
Example:
param \Illuminate\Contracts\Foundation\Application
$appreturn void
param
$nameparam
$valparam
$paramsreturn mixed|void
Sets a cookie with the given name and value.
You can set additional cookie params like domain
, path
, expires
, secure
in array passed as last argument.
param int
$maxRedirectsreturn void
Sets the maximum number of redirects that the Client can follow.
param array
$paramsreturn void
Sets SERVER parameters valid for all next requests.
this will remove old ones.
return void
Enables automatic redirects to be followed by the client.
return void
Prevents automatic redirects to be followed by the client.
param
$selectorparam array
$paramsparam ?string
$buttonreturn void
Submits the given form on the page, with the given form values. Pass the form fieldâs values as an array in the second parameter.
Although this function can be used as a short-hand version of
fillField()
, selectOption()
, click()
etc. it has some important
differences:
fillField()
or selectOption()
with
a missing field.Fields that are not provided will be filled by their values from the page,
or from any previous calls to fillField()
, selectOption()
etc.
You donât need to click the âSubmitâ button afterwards.
This command itself triggers the request to formâs action.
You can optionally specify which buttonâs value to include in the request with the last parameter (as an alternative to explicitly setting its value in the second parameter), as button values are not otherwise included in the request.
Examples:
For example, given this sample âSign Upâ form:
You could write the following to submit it:
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.
This function works well when paired with seeInFormFields()
for quickly testing CRUD interfaces and form validation logic.
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.
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:
The solution is to pass an array value:
param string
$namereturn void
Switch to iframe or frame on the page.
Example:
param
$optionreturn void
Unticks a checkbox.
param string
$name the name of the header to unset.return void
Unsets a HTTP header (that was originally added by haveHttpHeader()), so that subsequent requests will not send it anymore.
Example: