-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add browserkit component documentation #4312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
f4732a9
9cda982
33a3a64
9ae95dc
4d9e48d
59a9dbf
f956182
51f320a
d4c24e4
cd4f6ec
05c89d5
982476e
0923ac4
2731858
f119848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BrowserKit | ||
========== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
introduction |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.. index:: | ||
single: BrowserKit | ||
single: Components; BrowserKit | ||
|
||
The BrowserKit Component | ||
======================== | ||
|
||
The BrowserKit component simulates the behavior of a web browser. | ||
|
||
The BrowserKit component allows you to make web request, click on links and submit forms. | ||
|
||
Installation | ||
------------ | ||
|
||
You can install the component in 2 different ways: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "two" instead of "2" |
||
|
||
* :doc:`Install it via Composer </components/using_components>` (``symfony/browser-kit`` on `Packagist`_); | ||
* Use the official Git repository (https://github.com/symfony/BrowserKit). | ||
|
||
Usage | ||
----- | ||
|
||
.. note:: | ||
The component only provides an abstract client and does not provide any "default" backend for the HTTP layer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a blank line between the directive and its contents. |
||
|
||
Making Request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requests |
||
~~~~~~~~~~~~~~ | ||
|
||
To make a request you use the client's request method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
The first two arguments are for the HTTP method and the request url. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. URL |
||
The request method will return a crawler object. | ||
|
||
.. code-block:: php | ||
|
||
use ACME\Client; | ||
|
||
$client = new Client(); | ||
$crawler = $client->request('GET', 'http://symfony.com'); | ||
|
||
Clicking Links | ||
~~~~~~~~~~~~~~ | ||
|
||
select a link with the crawler and pass it to the click method to click on the link. | ||
|
||
.. code-block:: php | ||
|
||
use ACME\Client; | ||
|
||
$client = new Client(); | ||
$crawler = $client->request('GET', 'http://symfony.com'); | ||
$link = $crawler->selectLink('Go elsewhere...')->link(); | ||
$client->click($link); | ||
|
||
Submiting Forms | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Creating a Client | ||
----------------- | ||
|
||
For a simple implementation of a browser based on an HTTP layer, have a look at Goutte_. | ||
|
||
For an implementation based on HttpKernelInterface, have a look at the Client provided by the :doc:`/components/http_kernel/introduction`. | ||
|
||
.. _Packagist: https://packagist.org/packages/symfony/event-dispatcher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong link |
||
.. _Goutte: https://github.com/fabpot/Goutte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requests