You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+15-2Lines changed: 15 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,19 @@
1
1
CHANGELOG
2
2
=========
3
3
4
+
0.5.0
5
+
-----
6
+
7
+
* Add support for [Crawler test assertions](https://symfony.com/doc/current/testing/functional_tests_assertions.html#crawler)
8
+
* Add the `PantherTestCase::createAdditionalPantherClient()` to retrieve additional isolated browsers, useful to test applications using [Mercure](https://mercure.rocks) or [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
9
+
* Improved support for non-standard web server directories
10
+
* Allow the integrated web server to start even if the homepage doesn't return a 200 HTTP status code
11
+
* Increase default timeouts from 5 seconds to 30 seconds
12
+
* Improve error messages
13
+
* Add compatibility with Symfony 4.3
14
+
* Upgrade ChromeDriver to version 76.0.3809.68
15
+
* Various quality improvements
16
+
4
17
0.4.1
5
18
-----
6
19
@@ -22,7 +35,7 @@ CHANGELOG
22
35
* Keep the browser window open on fail, when running in non-headless mode
23
36
* Automatically open Chrome DevTools when running in non-headless mode
24
37
* PHPUnit 8 compatibility
25
-
* Add a PHPUnit extension to keep alive the webserver and the client between tests
38
+
* Add a PHPUnit extension to keep alive the web server and the client between tests
26
39
* Change the default port of the web server to `9080` to prevent a conflict with Xdebug
27
40
* Allow to use an external web server instead of the built-in one for testing
28
41
* Allow to use a custom router script
@@ -32,7 +45,7 @@ CHANGELOG
32
45
-----
33
46
34
47
* Add JS execution capabilities to `Client`
35
-
* Allow keeping the webserver and client active even after test teardown
48
+
* Allow keeping the web server and client active even after test teardown
36
49
* Add a method to refresh the crawler (`Client::refreshCrawler()`)
37
50
* Add options to configure the web server and ChromeDriver
@@ -22,9 +22,23 @@ so you don't need to install anything on your computer, neither Selenium server
22
22
In test mode, Panther automatically starts your application using [the PHP built-in web-server](http://php.net/manual/en/features.commandline.webserver.php).
23
23
You can focus on writing your tests or web-scraping scenario and Panther will take care of everything else.
24
24
25
-
## Install
25
+
## Features
26
+
27
+
Unlike testing and web scraping libraries you're used to, Panther:
28
+
29
+
* executes the JavaScript code contained in webpages
30
+
* supports everything that Chrome (or Firefox) implements
31
+
* allows screenshots taking
32
+
* can wait for asynchronously loaded elements to show up
33
+
* lets you run your own JS code or XPath queries in the context of the loaded page
* supports remote browser testing services including [SauceLabs](https://saucelabs.com/) and [BrowserStack](https://www.browserstack.com/)
36
+
37
+
## Documentation
26
38
27
-
Use [Composer](https://getcomposer.org/) to install Panther in your project. You may want to use the --dev flag if you want to use Panther for testing only and not for web scraping in a production environment:
39
+
### Install
40
+
41
+
Use [Composer](https://getcomposer.org/) to install Panther in your project. You may want to use the `--dev` flag if you want to use Panther for testing only and not for web scraping in a production environment:
28
42
29
43
composer req symfony/panther
30
44
@@ -33,18 +47,17 @@ Use [Composer](https://getcomposer.org/) to install Panther in your project. You
33
47
**Warning:** On \*nix systems, the `unzip` command must be installed or you will encounter an error similar to `RuntimeException: sh: 1: exec: /app/vendor/symfony/panther/src/ProcessManager/../../chromedriver-bin/chromedriver_linux64: Permission denied` (or `chromedriver_linux64: not found`).
34
48
The underlying reason is that PHP's `ZipArchive` doesn't preserve UNIX executable permissions.
The `PantherTestCase` class allows you to easily write E2E tests. It automatically starts your app using the built-in PHP
59
72
web server and let you crawl it using Panther.
60
-
It extends [PHPUnit](https://phpunit.de/)'s `TestCase` and provides all of the testing tools you're used to.
73
+
To provides all of the testing tools you're used to, it extends [PHPUnit](https://phpunit.de/)'s `TestCase`.
74
+
75
+
If you are testing a Symfony application, `PantherTestCase` automatically extends [the `WebTestCase` class](https://symfony.com/doc/current/testing.html#functional-tests).
76
+
It means you can easily create functional tests, which can directly execute the kernel of your application and access all
77
+
your existing services. In this case, you can use [all crawler test assertions](https://symfony.com/doc/current/testing/functional_tests_assertions.html#crawler)
78
+
provided by Symfony with Panther.
61
79
62
80
```php
63
81
<?php
@@ -68,12 +86,14 @@ use Symfony\Component\Panther\PantherTestCase;
68
86
69
87
class E2eTest extends PantherTestCase
70
88
{
71
-
public function testMyApp()
89
+
public function testMyApp(): void
72
90
{
73
91
$client = static::createPantherClient(); // Your app is automatically started using the built-in web server
74
-
$crawler = $client->request('GET', '/mypage');
92
+
$client->request('GET', '/mypage');
75
93
76
-
$this->assertContains('My Title', $crawler->filter('title')->html()); // You can use any PHPUnit assertion
94
+
// Use any PHPUnit assertion, including the ones provided by Symfony
If you are testing a Symfony application, `PantherTestCase` automatically extends the `WebTestCase` class. It means
88
-
you can easily create functional tests, which can directly execute the kernel of your application and access all your existing
89
-
services. Unlike the Panther's client, the Symfony's testing client doesn't support JavaScript and screenshots capturing, but
90
-
it is super-fast!
107
+
Panther also gives you instant access to other BrowserKit-based implementations of `Client` and `Crawler`.
108
+
Unlike Panther's native client, these alternative clients don't support JavaScript, CSS and screenshots capturing,
109
+
but they are **super-fast**!
91
110
92
-
Alternatively (and even for non-Symfony apps), Panther can also leverage the [Goutte](https://github.com/FriendsOfPHP/Goutte)
93
-
web scraping library, which is an intermediate between the Symfony's and the Panther's test clients. Goutte sends real HTTP
94
-
requests, it is fast and is able to browse any webpage, not only the ones of the application under test.
95
-
However, Goutte doesn't support JavaScript and other advanced features because it is entirely written in PHP.
111
+
Two alternative clients are available:
96
112
97
-
The fun part is that the 3 libraries implement the exact same API, so you can switch from one to another just by calling
113
+
* The first directly manipulates the Symfony kernel provided by `WebTestCase`, it's the fastest client available,
114
+
but it is only available for Symfony apps.
115
+
* The second leverages the [Goutte](https://github.com/FriendsOfPHP/Goutte) web scraping library.
116
+
It is an intermediate between the Symfony's and the Panther's test clients. Goutte sends real HTTP requests, it is fast
117
+
and is able to browse any webpage, not only the ones of the application under test.
118
+
However, Goutte doesn't support JavaScript and other advanced features because it is entirely written in PHP.
119
+
This one is available even for non-Symfony apps!
120
+
121
+
The fun part is that the 3 clients implement the exact same API, so you can switch from one to another just by calling
98
122
the appropriate factory method, resulting in a good trade-off for every single test case (Do I need JavaScript? Do I need
99
123
to authenticate with an external SSO server? Do I want to access the kernel of the current request? ... etc).
100
124
125
+
Here is how to retrieve instances of these clients:
126
+
101
127
```php
102
128
<?php
103
129
@@ -110,7 +136,7 @@ class E2eTest extends PantherTestCase
110
136
{
111
137
public function testMyApp()
112
138
{
113
-
$symfonyClient = static::createClient(); // A cute kitty: the Symfony's functional test too
139
+
$symfonyClient = static::createClient(); // A cute kitty: the Symfony's functional test tool
114
140
$goutteClient = static::createGoutteClient(); // An agile lynx: Goutte
115
141
$pantherClient = static::createPantherClient(); // A majestic Panther
116
142
// Both Goutte and Panther benefits from the built-in HTTP server
@@ -123,13 +149,74 @@ class E2eTest extends PantherTestCase
123
149
// enjoy the same API for the 3 felines
124
150
// $*client->request('GET', '...')
125
151
126
-
$kernel = static::createKernel(); // You have also access to the app's kernel
152
+
$kernel = static::createKernel(); // If you are testing a Symfony app, you also have access to the kernel
127
153
128
154
// ...
129
155
}
130
156
}
131
157
```
132
158
159
+
### Creating Isolated Browsers to Test Apps Using [Mercure](https://mercure.rocks) or WebSockets
160
+
161
+
Panther provides a convenient way to test applications with real-time capabilities which use [Mercure](https://symfony.com/doc/current/mercure.html), [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
162
+
and similar technologies.
163
+
164
+
The `PantherTestCase::createAdditionalPantherClient()` creates additional, isolated, browsers; that can interact with each others.
165
+
For instance, this can be useful to test a chat application having several users connected simultaneously:
166
+
167
+
```php
168
+
<?php
169
+
170
+
use Symfony\Component\Panther\PantherTestCase;
171
+
172
+
class ChatTest extends PantherTestCase
173
+
{
174
+
public function testChat(): void
175
+
{
176
+
$client1 = self::createPantherClient();
177
+
$client1->request('GET', '/chat');
178
+
179
+
// Connect a 2nd user using an isolated browser and say hi!
Since Panther implements the API of popular libraries, it already has an extensive documentation:
195
+
196
+
* For the `Client` class, read [the BrowserKit's documentation](https://symfony.com/doc/current/components/browser_kit.html)
197
+
* For the `Crawler` class, read [the DomCrawler's documentation](https://symfony.com/doc/current/components/dom_crawler.html)
198
+
* For Webdriver, read [the Facebook's PHP WebDriver documentation](https://github.com/facebook/php-webdriver)
199
+
200
+
### Environment Variables
201
+
202
+
The following environment variables can be set to change some Panther's behaviour:
203
+
204
+
*`PANTHER_NO_HEADLESS`: to disable browser's headless mode (will display the testing window, useful to debug)
205
+
*`PANTHER_NO_SANDBOX`: to disable [Chrome's sandboxing](https://chromium.googlesource.com/chromium/src/+/b4730a0c2773d8f6728946013eb812c6d3975bec/docs/design/sandbox.md) (unsafe, but allows to use Panther in containers)
206
+
*`PANTHER_WEB_SERVER_DIR`: to change the project's document root (default to `public/`)
207
+
*`PANTHER_CHROME_DRIVER_BINARY`: to use another `chromedriver` binary, instead of relying on the ones already provided by Panther
208
+
*`PANTHER_CHROME_ARGUMENTS`: to customize `chromedriver` arguments. You need to set `PANTHER_NO_HEADLESS` to fully customize.
209
+
*`PANTHER_WEB_SERVER_PORT`: to change the web server's port (default to `9080`)
210
+
*`PANTHER_WEB_SERVER_ROUTER`: to use a web server router script which is run at the start of each HTTP request
211
+
*`PANTHER_EXTERNAL_BASE_URI`: to use an external web server (the PHP built-in web server will not be started)
212
+
*`PANTHER_CHROME_BINARY`: to use another `google-chrome` binary
213
+
214
+
### Accessing To Hidden Text
215
+
216
+
According to the spec, WebDriver implementations returns only the **displayed** text by default.
217
+
When you filter on a head tag (like `title`), the method `text()` returns an empty string. Use the method `html()` to get
218
+
the complete contents of the tag, including the tag itself.
219
+
133
220
### Interactive Mode
134
221
135
222
Panther can make a pause in your tests suites after a failure.
@@ -144,27 +231,8 @@ For enabling this mode, you need the `--debug` PHPUnit option without the headle
144
231
145
232
Press enter to continue...
146
233
147
-
## Features
148
-
149
-
Unlike testing and web scraping libraries you're used to, Panther:
150
-
151
-
* executes the JavaScript code contained in webpages
152
-
* supports everything that Chrome (or Firefox) implements
153
-
* allows screenshots taking
154
-
* can wait for the appearance of asynchronously loaded elements
155
-
* lets you run your own JS code or XPath queries in the context of the loaded page
Webdriver returns only the displayed text. When you filter on a head tag (like `title`), the method `text()` returns an
227
-
empty string. Use the method `html()` to get the complete contents of the tag, including the tag itself.
228
-
229
-
### Environment Variables
230
-
231
-
The following environment variables can be set to change some Panther's behaviour:
232
-
233
-
*`PANTHER_NO_HEADLESS`: to disable browser's headless mode (will display the testing window, useful to debug)
234
-
*`PANTHER_NO_SANDBOX`: to disable [Chrome's sandboxing](https://chromium.googlesource.com/chromium/src/+/b4730a0c2773d8f6728946013eb812c6d3975bec/docs/design/sandbox.md) (unsafe, but allows to use Panther in containers)
235
-
*`PANTHER_WEB_SERVER_DIR`: to change the project's document root (default to `public/`)
236
-
*`PANTHER_CHROME_DRIVER_BINARY`: to use another `chromedriver` binary, instead of relying on the ones already provided by Panther
237
-
*`PANTHER_CHROME_ARGUMENTS`: to customize `chromedriver` arguments. You need to set `PANTHER_NO_HEADLESS` to fully customize.
238
-
*`PANTHER_WEB_SERVER_PORT`: to change the web server's port (default to `9080`)
239
-
*`PANTHER_WEB_SERVER_ROUTER`: to use a web server router script which is run at the start of each HTTP request
240
-
*`PANTHER_EXTERNAL_BASE_URI`: to use an external web server (the PHP built-in web server will not be started)
241
-
*`PANTHER_CHROME_BINARY`: to use another `google-chrome` binary
288
+
To use a proxy server, set the following environment variable: `PANTHER_CHROME_ARGUMENTS='--proxy-server=socks://127.0.0.1:9050'`
0 commit comments