Skip to content

Commit 6cc2186

Browse files
committed
Document the assertion system
1 parent e7f9322 commit 6cc2186

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

guides/traversing-pages.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@ that you can make same old traversing on such elements as well:
8181
8282
// find some field INSIDE form with class="register"
8383
$field = $registerForm->findField('Email');
84+
85+
Webassert
86+
~~~~~~~~~
87+
88+
The ``\Behat\Mink\WebAssert`` class provides a set of assertion. There are assertions
89+
about the address of the page, the cookies, the status code, the response headers,
90+
the content of the page, the page elements... An assertion can improve code readability
91+
and avoid having a fatal error in method chaining.
92+
93+
For example, instead of:
94+
95+
.. code-block:: php
96+
97+
$registerForm = $page->find('css', 'form.register');
98+
99+
if (null === $registerForm) {
100+
throw new \Exception('The element is not found');
101+
}
102+
103+
// find some field INSIDE form with class="register"
104+
$field = $registerForm->findField('Email');
105+
106+
you can do:
107+
108+
.. code-block:: php
109+
110+
field = $mink->assertSession()->fieldExists(
111+
'Email',
112+
// Throw exception when not found instead of returning null.
113+
$mink->assertSession()->elementExists('css', 'form.register')
114+
);
84115
85116
.. _selectors:
86117

0 commit comments

Comments
 (0)