-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Assertion system | ||
================ | ||
|
||
The ``\Behat\Mink\WebAssert`` class provides a set of assertions. There are assertions | ||
about the address of the page, the cookies, the status code, the response headers, | ||
the content of the page, the page elements... | ||
|
||
API with exceptions | ||
------------------- | ||
|
||
An assertion can improve code readability and avoid having a fatal error in method chaining. | ||
|
||
For example, instead of: | ||
|
||
.. code-block:: php | ||
$registerForm = $page->find('css', 'form.register'); | ||
if (null === $registerForm) { | ||
throw new \Exception('The element is not found'); | ||
} | ||
$field = $registerForm->findField('Email'); | ||
if (null === $field) { | ||
throw new \Exception('The element is not found'); | ||
} | ||
$field->setValue('[email protected]'); | ||
you can do: | ||
|
||
.. code-block:: php | ||
// Throw exception when not found instead of returning null. | ||
$registerForm = $mink->assertSession()->elementExists('css', 'form.register'); | ||
$field = $mink->assertSession()->fieldExists('Email', $registerForm); | ||
$field->setValue('[email protected]'); | ||
Webassert and multisessions | ||
--------------------------- | ||
|
||
You could use an another session by calling ``assertSession`` with a session name | ||
or an instance of ``\Behat\Mink\Session``. | ||
|
||
.. code-block:: php | ||
$mink->assertSession()->elementExists('css', 'form.register'); | ||
$mink->assertSession('goutte')->elementExists('css', 'form.register'); | ||
$mink->assertSession($mink->getSession('goutte'))->elementExists('css', 'form.register'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters