Skip to content

Commit

Permalink
feat: allow selenium server with internal webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
daFish committed Dec 4, 2024
1 parent 8c86705 commit 0a971e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ class SecondDomainTest extends PantherTestCase

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

### Using Selenium With the Built-In Web Server

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:

```php
$client = Client::createPantherClient(
options: [
'browser' => PantherTestCase::SELENIUM,
],
managerOptions: [
'host' => 'http://selenium-hub:4444', // the host of the Selenium Server (Grid)
'capabilities' => DesiredCapabilities::firefox(), // the capabilities of the browser
],
);
```

### Accepting Self-signed SSL Certificates

To force Chrome to accept invalid and self-signed certificates, set the following environment variable: `PANTHER_CHROME_ARGUMENTS='--ignore-certificate-errors'`
Expand Down
2 changes: 2 additions & 0 deletions src/PantherTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class PantherTestCase extends WebTestCase

public const CHROME = 'chrome';
public const FIREFOX = 'firefox';
public const SELENIUM = 'selenium';

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

public const CHROME = 'chrome';
public const FIREFOX = 'firefox';
public const SELENIUM = 'selenium';

protected function tearDown(): void
{
Expand Down
4 changes: 3 additions & 1 deletion src/PantherTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ protected static function createPantherClient(array $options = [], array $kernel

if (PantherTestCase::FIREFOX === $browser) {
self::$pantherClients[0] = self::$pantherClient = PantherClient::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri);
} else {
} elseif (PantherTestCase::SELENIUM === $browser) {
self::$pantherClients[0] = self::$pantherClient = PantherClient::createSeleniumClient($managerOptions['host'], $managerOptions['capabilities'] ?? null, self::$baseUri, $options);
} else {
try {
self::$pantherClients[0] = self::$pantherClient = PantherClient::createChromeClient(null, $browserArguments, $managerOptions, self::$baseUri);
} catch (\RuntimeException $e) {
Expand Down

0 comments on commit 0a971e3

Please sign in to comment.