symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.93k stars 219 forks source link

Unable to run even a basic test #605

Open aruku opened 1 year ago

aruku commented 1 year ago

I've been fighting with Panther and Selenium for two or three days on and off at this point, and so far they both keep eluding me. I've given up on using Selenium Grid to use a remote browser and I just want to get the basic testing example to work. I'm using the provided Dockerfile through Compose so I can specify the same network as the rest of my project; I have also changed PANTHER_NO_SANDBOX to false. Then, for the test, I made the following modifications trying to understand what arguments, options and capabilities are needed:

    public function testMyApp(): void
    {
//        dd($_SERVER);

        $arguments = ['--headless', '--window-size=1200,1100', '--disable-gpu'];
        $options = [
            'scheme' => 'https',
            'host' => 'NAME',
            'path' => '/',
            'chromedriver_arguments' => [],
            'capabilities' => ['acceptInsecureCerts' => true],
            'external_base_uri' => 'NAME',
        ];
        $client = Client::createChromeClient('/usr/bin/chromedriver', $arguments, $options, 'NAME'); // Your app is automatically started using the built-in web server
        $client->request('GET', '/');

        [...]

I get this error:

1) App\Tests\E2E\pantherTest::testMyApp
RuntimeException: Could not connect to chrome after 30 seconds (OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to NAME:9515  for "https://NAME:9515/".).

I have replaced the actual local name for NAME in these snippets. Before it times out, I can see the panther and chromedriver processes spawning, but that is as far as I get. What I'm doing wrong?

Any feedback would be greatly appreciated.

halfer commented 12 months ago

I wonder if you need to use Client::createSeleniumClient()? I would guess that the browser-specific static methods are for the WebDriver implementation, not Selenium.

halfer commented 12 months ago

FWIW, I have set up a remote Geckodriver instance (instrumentisto/geckodriver) instead of Selenium and that seems to work well. However Panther had to rather be hacked to get it to work:

I will stick with what I have, but it is not great code. The authors of Panther really did not want it to be extended in this fashion! Perhaps I will submit an improvement request, so that this can be done in a more elegant way.

Now that I look at it afresh, it might have been easier just to copy FirefoxManager and amend the start() method in situ. Still not a nice solution though.

For now, if you want to run your browser as a separate container, using Selenium probably is the most straightforward way.