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: README.md
+79-65Lines changed: 79 additions & 65 deletions
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,8 @@ all the features you need to test your apps. It will sound familiar if you have
15
15
as the API is exactly the same!
16
16
Keep in mind that Panther can be used in every PHP project, as it is a standalone library.
17
17
18
-
Panther automatically finds your local installation of Chrome or Firefox and launches them (thanks to [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) and [GeckoDriver](https://github.com/mozilla/geckodriver)),
19
-
so you don't need to install anything on your computer, neither Selenium server nor any other obscure driver.
18
+
Panther automatically finds your local installation of Chrome or Firefox and launches them,
19
+
so you don't need to install anything else on your computer, a Selenium server is not needed!
20
20
21
21
In test mode, Panther automatically starts your application using [the PHP built-in web-server](http://php.net/manual/en/features.commandline.webserver.php).
22
22
You can focus on writing your tests or web-scraping scenario and Panther will take care of everything else.
@@ -27,28 +27,57 @@ Unlike testing and web scraping libraries you're used to, Panther:
27
27
28
28
* executes the JavaScript code contained in webpages
29
29
* supports everything that Chrome (or Firefox) implements
30
-
* allows screenshots taking
30
+
* allows taking screenshots
31
31
* can wait for asynchronously loaded elements to show up
32
32
* 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/)
35
35
36
36
## Documentation
37
37
38
-
### Install
38
+
### Installing Panther
39
39
40
40
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:
41
41
42
42
composer req symfony/panther
43
43
44
44
composer req --dev symfony/panther
45
45
46
-
**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`).
46
+
**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`).
47
47
The underlying reason is that PHP's `ZipArchive` doesn't preserve UNIX executable permissions.
48
48
49
+
### Installing ChromeDriver and geckodriver
50
+
51
+
Panther uses the WebDriver protocol to control the browser used to crawl websites.
52
+
53
+
On all systems, you can use `dbrekelmans/browser-driver-installer` to install ChromeDriver and geckodriver locally:
54
+
55
+
composer require --dev dbrekelmans/bdi
56
+
vendor/bin/bdi detect drivers
57
+
58
+
Panther will detect and use automatically drivers stored in the `drivers/` directory.
59
+
60
+
Alternatively, you can use the package manager of your operating system to install them.
The `PantherTestCase` class allows you to easily write E2E tests. It automatically starts your app using the built-in PHP
105
136
web server and let you crawl it using Panther.
106
-
To provide all of the testing tools you're used to, it extends [PHPUnit](https://phpunit.de/)'s `TestCase`.
137
+
To provide all the testing tools you're used to, it extends [PHPUnit](https://phpunit.de/)'s `TestCase`.
107
138
108
139
If you are testing a Symfony application, `PantherTestCase` automatically extends [the `WebTestCase` class](https://symfony.com/doc/current/testing.html#functional-tests).
109
140
It means you can easily create functional tests, which can directly execute the kernel of your application and access all
@@ -243,11 +274,11 @@ class ChatTest extends PantherTestCase
243
274
244
275
### Checking the State of the WebDriver Connection
245
276
246
-
Use the `Client::ping()` method to check if the WebDriver connection is still active (useful for longrunning tasks).
277
+
Use the `Client::ping()` method to check if the WebDriver connection is still active (useful for long-running tasks).
247
278
248
279
## Additional Documentation
249
280
250
-
Since Panther implements the API of popular libraries, it already has extensive documentation:
281
+
Since Panther implements the API of popular libraries, it already has an extensive documentation:
251
282
252
283
* For the `Client` class, read [the BrowserKit documentation](https://symfony.com/doc/current/components/browser_kit.html)
253
284
* For the `Crawler` class, read [the DomCrawler documentation](https://symfony.com/doc/current/components/dom_crawler.html)
@@ -257,7 +288,7 @@ Since Panther implements the API of popular libraries, it already has extensive
257
288
258
289
The following environment variables can be set to change some Panther's behaviour:
259
290
260
-
*`PANTHER_NO_HEADLESS`: to disable browser's headless mode (will display the testing window, useful to debug)
291
+
*`PANTHER_NO_HEADLESS`: to disable the browser's headless mode (will display the testing window, useful to debug)
261
292
*`PANTHER_WEB_SERVER_DIR`: to change the project's document root (default to `./public/`, relative paths **must start** by `./`)
262
293
*`PANTHER_WEB_SERVER_PORT`: to change the web server's port (default to `9080`)
263
294
*`PANTHER_WEB_SERVER_ROUTER`: to use a web server router script which is run at the start of each HTTP request
*`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)
282
-
*`PANTHER_CHROME_DRIVER_BINARY`: to use another `chromedriver` binary, instead of relying on the ones already provided by Panther
283
313
*`PANTHER_CHROME_ARGUMENTS`: to customize Chrome arguments. You need to set `PANTHER_NO_HEADLESS` to fully customize.
284
314
*`PANTHER_CHROME_BINARY`: to use another `google-chrome` binary
285
315
286
316
#### Firefox-specific Environment Variables
287
317
288
-
*`PANTHER_GECKO_DRIVER_BINARY`: to use another `geckodriver` binary, instead of relying on the ones already provided by Panther
289
318
*`PANTHER_FIREFOX_ARGUMENTS`: to customize Firefox arguments. You need to set `PANTHER_NO_HEADLESS` to fully customize.
290
319
*`PANTHER_FIREFOX_BINARY`: to use another `firefox` binary
291
320
@@ -344,29 +373,29 @@ To force Chrome to accept invalid and self-signed certificates, set the followin
344
373
345
374
### Docker Integration
346
375
347
-
Here is a minimal Docker image that can run Panther:
376
+
Here is a minimal Docker image that can run Panther with both Chrome and Firefox:
348
377
349
-
```
350
-
FROM php:latest
378
+
```Dockerfile
379
+
FROM php:alpine
351
380
352
-
RUN apt-get update && apt-get install -y libzip-dev zlib1g-dev chromium && docker-php-ext-install zip
If you want to use Panther with other testing tools like [LiipFunctionalTestBundle](https://github.com/liip/LiipFunctionalTestBundle) or if you just need to use a different base class, Panther has got you covered. It provides you with the `Symfony\Component\Panther\PantherTestCaseTrait` and you can use it to enhance your existing test-infrastructure with some Panther awesomeness:
502
+
If you want to use Panther with other testing tools like [LiipFunctionalTestBundle](https://github.com/liip/LiipFunctionalTestBundle)
503
+
or if you just need to use a different base class, Panther has got you covered.
504
+
It provides you with the `Symfony\Component\Panther\PantherTestCaseTrait` and you can use it to enhance your existing
505
+
test-infrastructure with some Panther awesomeness:
493
506
494
507
```php
495
508
<?php
@@ -534,4 +547,5 @@ If you like this software, help save the (real) panthers by [donating to the Pan
534
547
535
548
Created by [Kévin Dunglas](https://dunglas.fr). Sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).
536
549
537
-
Panther is built on top of [PHP WebDriver](https://github.com/php-webdriver/php-webdriver) and [several other FOSS libraries](https://symfony.com/blog/introducing-symfony-panther-a-browser-testing-and-web-scrapping-library-for-php#thank-you-open-source). It has been inspired by [Nightwatch.js](http://nightwatchjs.org/), a WebDriver-based testing tool for JavaScript.
550
+
Panther is built on top of [PHP WebDriver](https://github.com/php-webdriver/php-webdriver) and [several other FOSS libraries](https://symfony.com/blog/introducing-symfony-panther-a-browser-testing-and-web-scrapping-library-for-php#thank-you-open-source).
551
+
It has been inspired by [Nightwatch.js](http://nightwatchjs.org/), a WebDriver-based testing tool for JavaScript.
if ($binary = $_SERVER['PANTHER_CHROME_DRIVER_BINARY'] ?? null) {
85
+
@trigger_error('The "PANTHER_CHROME_DRIVER_BINARY" environment variable is deprecated since Panther 0.9, add ChromeDriver to your PATH instead.', E_USER_DEPRECATED);
if ($binary = (newExecutableFinder())->find('chromedriver', null, ['./drivers'])) {
91
+
return$binary;
88
92
}
93
+
94
+
thrownew \RuntimeException('"chromedriver" binary not found. Install it using the package manager of your operating system or by running "composer require --dev dbrekelmans/bdi && vendor/bin/bdi detect drivers".');
0 commit comments