Skip to content

Commit c136f5f

Browse files
daFishdunglas
authored andcommitted
feat: allow selenium server with internal webserver
1 parent 4009127 commit c136f5f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,22 @@ class SecondDomainTest extends PantherTestCase
498498

499499
To use a proxy server, set the following environment variable: `PANTHER_CHROME_ARGUMENTS='--proxy-server=socks://127.0.0.1:9050'`
500500

501+
### Using Selenium With the Built-In Web Server
502+
503+
If you want to use [Selenium Grid](https://www.selenium.dev/documentation/grid/) with the built-in web server, you need to configure the Panther client as follows:
504+
505+
```php
506+
$client = Client::createPantherClient(
507+
options: [
508+
'browser' => PantherTestCase::SELENIUM,
509+
],
510+
managerOptions: [
511+
'host' => 'http://selenium-hub:4444', // the host of the Selenium Server (Grid)
512+
'capabilities' => DesiredCapabilities::firefox(), // the capabilities of the browser
513+
],
514+
);
515+
```
516+
501517
### Accepting Self-signed SSL Certificates
502518

503519
To force Chrome to accept invalid and self-signed certificates, set the following environment variable: `PANTHER_CHROME_ARGUMENTS='--ignore-certificate-errors'`

src/PantherTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class PantherTestCase extends WebTestCase
2323

2424
public const CHROME = 'chrome';
2525
public const FIREFOX = 'firefox';
26+
public const SELENIUM = 'selenium';
2627

2728
protected function tearDown(): void
2829
{
@@ -44,6 +45,7 @@ abstract class PantherTestCase extends TestCase
4445

4546
public const CHROME = 'chrome';
4647
public const FIREFOX = 'firefox';
48+
public const SELENIUM = 'selenium';
4749

4850
protected function tearDown(): void
4951
{

src/PantherTestCaseTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ protected static function createPantherClient(array $options = [], array $kernel
186186

187187
if (PantherTestCase::FIREFOX === $browser) {
188188
self::$pantherClients[0] = self::$pantherClient = PantherClient::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri);
189+
} elseif (PantherTestCase::SELENIUM === $browser) {
190+
self::$pantherClients[0] = self::$pantherClient = PantherClient::createSeleniumClient($managerOptions['host'], $managerOptions['capabilities'] ?? null, self::$baseUri, $options);
189191
} else {
190192
try {
191193
self::$pantherClients[0] = self::$pantherClient = PantherClient::createChromeClient(null, $browserArguments, $managerOptions, self::$baseUri);

0 commit comments

Comments
 (0)