Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example using Panther with remote Chrome instance in Docker (with Behat) #590

Open
dkarlovi opened this issue Mar 2, 2023 · 0 comments
Open

Comments

@dkarlovi
Copy link

dkarlovi commented Mar 2, 2023

Compose file:

# docker-compose.yaml
services:
    web: # my app with PHP, but without Chrome
        image: app:latest
    chrome:
        image: selenium/standalone-chrome
        shm_size: 2gb

Behat config, using https://github.com/robertfausk/behat-panther-extension:

# behat.yaml.dist
default:
    extensions:
        Robertfausk\Behat\PantherExtension: ~
        FriendsOfBehat\SymfonyExtension:
            bootstrap: tests/bootstrap.php
        Behat\MinkExtension:
            base_url: http://web/
            javascript_session: panther
            sessions:
                symfony:
                    symfony: ~
                panther:
                    panther:
                        manager_options:
                            host: http://chrome:4444/wd/hub

Patch for Panther

Selenium is not supported here so I patch this file:

self::startWebServer($options);
if (PantherTestCase::CHROME === $browser) {
self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri);
} else {
self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
}

like so:

--- /dev/null
+++ ../src/PantherTestCaseTrait.php
@@ -161,12 +161,16 @@
         }

         self::startWebServer($options);
+        self::$pantherClients[0] = self::$pantherClient = Client::createSeleniumClient($managerOptions['host'], null, self::$baseUri);

+        /*
         if (PantherTestCase::CHROME === $browser) {
             self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri);
         } else {
             self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
         }
+        */

         if (is_a(self::class, KernelTestCase::class, true)) {
             static::bootKernel($kernelOptions); // @phpstan-ignore-line

This works as expected, the patch could be made into a PR by somebody and it would work out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant