diff --git a/README.md b/README.md index 8a809bb1..626c72d9 100644 --- a/README.md +++ b/README.md @@ -498,6 +498,20 @@ 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 with the built-in web server, you need to configure the panther client as follows: + +```php +$client = Client::createPantherClient( + host: 'http://firefox:4444', // the host of the selenium server + capabilities: DesiredCapabilities::firefox(), // the capabilities of the browser + options: [ + 'browser' => PantherTestCase::SELENIUM, + ], +); +``` + ### 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'` diff --git a/src/PantherTestCase.php b/src/PantherTestCase.php index d92af2f8..7bf9d0ca 100644 --- a/src/PantherTestCase.php +++ b/src/PantherTestCase.php @@ -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 { @@ -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 { diff --git a/src/PantherTestCaseTrait.php b/src/PantherTestCaseTrait.php index 5c8ea2b1..b943a198 100644 --- a/src/PantherTestCaseTrait.php +++ b/src/PantherTestCaseTrait.php @@ -180,7 +180,9 @@ protected static function createPantherClient(array $options = [], array $kernel if (PantherTestCase::FIREFOX === $browser) { self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri); - } else { + } elseif (PantherTestCase::SELENIUM === $browser) { + self::$pantherClients[0] = self::$pantherClient = Client::createSeleniumClient($managerOptions['host'], $managerOptions['capabilities'], self::$baseUri, $options); + } else { try { self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri); } catch (\RuntimeException $e) {