@@ -151,12 +151,9 @@ As an example, a test could look like this::
151
151
{
152
152
$client = static::createClient();
153
153
154
- $crawler = $ client->request('GET', '/post/hello-world');
154
+ $client->request('GET', '/post/hello-world');
155
155
156
- $this->assertGreaterThan(
157
- 0,
158
- $crawler->filter('html:contains("Hello World")')->count()
159
- );
156
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
160
157
}
161
158
}
162
159
@@ -182,6 +179,8 @@ As an example, a test could look like this::
182
179
``createKernel() `` or ``getKernelClass() `` methods of your functional test,
183
180
which take precedence over the ``KERNEL_CLASS `` env var.
184
181
182
+ In the above example, you validated that the HTTP response was successful. The
183
+ next step is to validate that the page actually contains the expected content.
185
184
The ``createClient() `` method returns a client, which is like a browser that
186
185
you'll use to crawl your site::
187
186
@@ -197,8 +196,25 @@ be used to select elements in the response, click on links and submit forms.
197
196
The ``Crawler `` only works when the response is an XML or an HTML document.
198
197
To get the raw content response, call ``$client->getResponse()->getContent() ``.
199
198
200
- Click on a link by first selecting it with the crawler using either an XPath
201
- expression or a CSS selector, then use the client to click on it. For example::
199
+ The crawler integrates with the ``symfony/css-selector `` component to give you the
200
+ power of CSS selectors to find content in a page. To install the CSS selector
201
+ component, run:
202
+
203
+ .. code-block :: terminal
204
+
205
+ $ composer require --dev css-selector
206
+
207
+ Now you can use CSS selectors with the crawler. To assert that the phrase
208
+ "Hello World" is on the page at least once, you can use this assertion::
209
+
210
+ $this->assertGreaterThan(
211
+ 0,
212
+ $crawler->filter('html:contains("Hello World")')->count()
213
+ );
214
+
215
+ The crawler can also be used to interact with the page. Click on a link by first
216
+ selecting it with the crawler using either an XPath expression or a CSS selector,
217
+ then use the client to click on it::
202
218
203
219
$link = $crawler
204
220
->filter('a:contains("Greet")') // find all links with the text "Greet"
0 commit comments