Testomatio - Test Management for Codeception
This module allows you to run tests inside Mezzio.
Uses config/container.php
file by default.
container
- (default: config/container.php
) relative path to file which returns ContainerrecreateApplicationBetweenTests
- (default: false) whether to recreate the whole application before each testrecreateApplicationBetweenRequests
- (default: false) whether to recreate the whole application before each request\Mezzio\Application
\Interop\Container\ContainerInterface
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 string
$usernameparam string
$passwordreturn void
Authenticates user for HTTP_AUTH
param string
$pagereturn void
Opens the page for the given relative URI.
param
$fieldparam string
$filenamereturn void
Attaches a file relative to the Codeception _data
directory to the given file upload field.
param
$optionreturn void
Ticks a checkbox. For radio buttons, use the selectOption
method instead.
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
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
$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
$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
$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.
param int
$codereturn void
Checks that response code is equal to value provided.
param
$fieldparam
$valuereturn void
Fills a text field or textarea with the given string.
return void
Follow pending redirect if there is one.
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.
throws \Codeception\Exception\ModuleException
if no page was opened.return string
Current page source code.Grabs current page source code.
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.
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 string
$nameparam string
$valuereturn void
Sets SERVER parameter valid for all next requests.
param ?string
$namereturn void
Use this method within an interactive pause to save the HTML source code of the current page.
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
$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
$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
$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
$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.
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.
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
$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
$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: