Testomatio - Test Management for Codeception
If you use Codeception installed using composer, install this module with the following command:
Alternatively, you can enable Phalcon4
module in suite configuration file and run
This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.
This module provides integration with Phalcon framework (4.x). Please try it and leave your feedback.
The following configurations are required for this module:
string
, default app/config/bootstrap.php
- relative path to app.php config fileboolean
, default true
- all database queries will be run in a transaction,
which will be rolled back at the end of each testboolean
, default true
- use savepoints to emulate nested transactionsThe application bootstrap file must return Application object but not call its handle() method.
Phalcon\Di\Injectable
instanceBrowserKit
clientBy default all available methods are loaded, but you can specify parts to select only needed actions and avoid conflicts.
orm
- include only haveRecord/grabRecord/seeRecord/dontSeeRecord
actions.services
- allows to use grabServiceFromContainer
and addServiceToContainer
.See WebDriver module for general information on how to load parts of a framework module.
Usage example:
Sample bootstrap (app/config/bootstrap.php
):
hidden API method, expected to be used from Helper classes
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
param
$locatorreturn array
of interactive elementshidden API method, expected to be used from Helper classes
Returns content of the last response Use it in Helpers when you want to retrieve response of request performed by another module.
return string
@throws ModuleExceptionhidden API method, expected to be used from Helper classes
Opens a page with arbitrary request parameters. Useful for testing multi-step forms on a specific step.
param string
$methodparam string
$uriparam string
$contenthidden API method, expected to be used from Helper classes
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.
param string
$methodparam string
$uriparam string
$contentreturn string
@throws ExternalUrlException
@see _loadPage
hidden API method, expected to be used from Helper classes
Saves page source of to a file
param
$filenameRegisters a service in the services container and resolve it. This record will be erased after the test. Recommended to use for unit testing.
param string
$nameparam mixed
$definitionparam boolean
$sharedreturn mixed|null
[Part]
servicesAuthenticates user for HTTP_AUTH
param string
$usernameparam string
$passwordOpens the page for the given relative URI.
param string
$pageOpens web page using route name and parameters.
param string
$routeNameparam array
$paramsAttaches a file relative to the Codeception _data
directory to the given file upload field.
param
$fieldparam
$filenameTicks a checkbox. For radio buttons, use the selectOption
method instead.
param
$optionPerform 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.
param
$linkparam
$contextDeletes the header with the passed name. Subsequent requests will not have the deleted header in its request.
Example:
param string
$name the name of the header to delete.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
$textparam array|string
$selector optionalCheck that the specified checkbox is unchecked.
param
$checkboxChecks 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
$cookie
param array
$params
Checks that the current URL doesnât equal the given string.
Unlike dontSeeInCurrentUrl
, this only matches the full URL.
param string
$uriChecks that current url doesnât match the given regular expression.
param string
$uriChecks that the given element is invisible or not present on the page. You can also specify expected attributes of this element.
param
$selectorparam array
$attributesChecks that the current URI doesnât contain the given string.
param string
$uriChecks 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
$fieldparam
$valueChecks 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
$formSelectorparam
$paramsChecks that the current page contains the given string in its raw source code.
param
$rawChecks that the page title does not contain the given string.
param
$titleChecks 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 string
$textparam string
$url optionalChecks that the given option is not selected.
param
$selectorparam
$optionTextChecks that record does not exist in database.
param string
$model Model nameparam array
$attributes Model attributes[Part]
ormChecks that response code is equal to value provided.
param int
$codeFills a text field or textarea with the given string.
param
$fieldparam
$valueFollow pending redirect if there is one.
Provides access the Phalcon application object.
@see \Codeception\Lib\Connector\Phalcon::getApplication
return \Phalcon\Application|\Phalcon\Mvc\Micro
Grabs the value of the given attribute value from the given element. Fails if element is not found.
param
$cssOrXpathparam
$attributeGrabs 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
$cookie
param array
$params
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 string
$uri optionalGrabs either the text content, or attribute values, of nodes matched by $cssOrXpath and returns them as an array.
param
$cssOrXpathparam
$attributereturn string[]
Grabs current page source code.
@throws ModuleException if no page was opened.
return string
Current page source code.Retrieves record from database
param string
$model Model nameparam array
$attributes Model attributes[Part]
ormResolves the service based on its configuration from Phalconâs DI container Recommended to use for unit testing.
param string
$service Service nameparam array
$parameters Parameters [Optional][Part]
servicesFinds 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
$cssOrXPathOrRegexparam
$field
return array|mixed|null|string
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 string
$name the name of the request headerparam string
$value the value to set it to for subsequent
requestsSets value to session. Use for authorization.
param string
$keyparam mixed
$valInserts record into the database.
param string
$model Model nameparam array
$attributes Model attributes[Part]
ormSets SERVER parameter valid for all next requests.
param string
$nameparam string
$valueUse this method within an interactive pause to save the HTML source code of the current page.
param null
$nameMoves back in history.
param int
$numberOfSteps (default value 1)Unsets cookie with the given name.
You can set additional cookie params like domain
, path
in array passed as last argument.
param
$cookie
param array
$params
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
$textparam array|string
$selector optionalChecks that the specified checkbox is checked.
param
$checkboxChecks 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
$cookieparam array
$paramsChecks that current url matches route
param string
$routeNameChecks that the current URL is equal to the given string.
Unlike seeInCurrentUrl
, this only matches the full URL.
param string
$uriChecks that the current URL matches the given regular expression.
param string
$uriChecks that the given element exists on the page and is visible. You can also specify expected attributes of this element.
param
$selectorparam array
$attributesChecks that current URI contains the given string.
param string
$uriChecks 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
$fieldparam
$valueChecks 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
$formSelectorparam
$paramsChecks that session contains value.
If value is null
checks that session has key.
param string
$keyparam mixed
$valueChecks that the current page contains the given string in its raw source code.
param
$rawChecks that the page title contains the given string.
param
$titleChecks that thereâs a link with the specified text. Give a full URL as the second parameter to match links with that exact URL.
param string
$textparam string
$url optionalChecks that there are a certain number of elements matched by the given locator on the page.
param
$selectorparam mixed
$expected int or int[]Checks that number of records exists in database.
param string
$model Model nameparam int
$number int number of recordsparam array
$attributes Model attributes[Part]
ormChecks that the given option is selected.
param
$selectorparam
$optionTextAsserts that current page has 404 response status code.
Checks that record exists in database.
param string
$model Model nameparam array
$attributes Model attributes[Part]
ormChecks that response code is equal to value provided.
param int
$codeChecks that response code is between a certain range. Between actually means [from <= CODE <= to]
param int
$fromparam int
$toChecks that the response code is 4xx
Checks that the response code 3xx
Checks that the response code is 5xx
Checks that the response code 2xx
Assert that the session has a given list of values.
param
array $bindingsreturn 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
$selectparam
$optionSends an ajax GET request with the passed parameters.
See sendAjaxPostRequest()
param
$uriparam
$paramsSends 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
$uriparam array
$paramsSends an ajax request, using the passed HTTP method.
See sendAjaxPostRequest()
Example:
param
$methodparam
$uriparam array
$paramsSets 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
$nameparam
$valparam array
$paramsSets the maximum number of redirects that the Client can follow.
param int
$maxRedirectsSets SERVER parameters valid for all next requests. this will remove old ones.
Enables automatic redirects to be followed by the client.
Prevents automatic redirects to be followed by the client.
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
$selectorparam
$paramsparam
$buttonSwitch to iframe or frame on the page.
Example:
param string
$nameUnticks a checkbox.
param
$option