Skip to content

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

Closed
wants to merge 15 commits into from
Closed
7 changes: 7 additions & 0 deletions components/browser_kit/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BrowserKit
==========

.. toctree::
:maxdepth: 2

introduction
65 changes: 65 additions & 0 deletions components/browser_kit/introduction.rst
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requests


Installation
------------

You can install the component in 2 different ways:
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requests

~~~~~~~~~~~~~~

To make a request you use the client's request method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the method role to link to the API docs of the request() method here.

The first two arguments are for the HTTP method and the request url.
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong link

.. _Goutte: https://github.com/fabpot/Goutte
1 change: 1 addition & 0 deletions components/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The Components
:hidden:

using_components
browser_kit/index
class_loader/index
config/index
console/index
Expand Down
4 changes: 4 additions & 0 deletions components/map.rst.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
* :doc:`/components/using_components`

* :doc:`/components/browser_kit/index`

* :doc:`/components/browser_kit/introduction`

* :doc:`/components/class_loader/index`

* :doc:`/components/class_loader/introduction`
Expand Down