panther
panther copied to clipboard
Docker / Panther Chrome DevToolsActivePort error
Hi,
Could you help me, I like to use Panther in a docker container but phpunit returns an error "DevToolsActivePort file doesn't exist" ?
1) App\Tests\FirstTest::testSomething
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming t
hat Chrome has crashed.)
With xDebug i can see the problem in vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php on line 320 : $raw_results = trim(curl_exec($this->curl));
Before this line, I can see chromedriver with "ps -x" command :
177 root 0:00 /usr/bin/chromedriver --port=9515
Dockerfile
FROM php:7.3-fpm-alpine
...
ENV PANTHER_NO_SANDBOX 1
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage'
RUN apk add unzip libzip-dev chromium chromium-chromedriver;
composer.json
"require-dev": {
"symfony/maker-bundle": "^1.20"
"dbrekelmans/bdi": "^0.3.0",
"symfony/css-selector": "4.4.*",
"symfony/maker-bundle": "^1.20",
"symfony/panther": "^1.0",
"symfony/phpunit-bridge": "^5.2"
},
/usr/lib/chromium/chrome --version
Chromium 86.0.4240.111
/usr/bin/chromedriver -v
ChromeDriver 86.0.4240.111 (b8c36128a06ebad76af51591bfec980224db5522-refs/branch-heads/4240@{#1290})
PantherTestCase
<?php
namespace App\Tests;
use Symfony\Component\Panther\Client;
use Symfony\Component\Panther\PantherTestCase;
class FirstTest extends PantherTestCase
{
public function testSomething()
{
$client = static::createPantherClient([
'--headless',
'--no-sandbox',
'--disable-dev-shm-usage',
'--remote-debugging-port=9100'
]);
$client->request('GET', 'https://api-platform.com'); // Yes, this website is 100% written in JavaScript
$client->clickLink('Get started');
// Wait for an element to be present in the DOM (even if hidden)
$crawler = $client->waitFor('#installing-the-framework');
// Alternatively, wait for an element to be visible
$crawler = $client->waitForVisibility('#installing-the-framework');
echo $crawler->filter('#installing-the-framework')->text();
$client->takeScreenshot('screen.png'); // Yeah, screenshot!
}
}
Thanks for your help.
Regards
Hi, Too me, I have this problem.
Regards
Same issue here!
I'm experiencing this issue as well
IDK whether this can be of any help, but I noticed the error was occurring even before the actual test method was run - I could delete its whole contents and the problem still persisted, so probably there was some check being executed in a setUp method or something like that. I wanted to switch Panther to Firefox, but the change was not being considered because the problem occurred before static::createPantherClient(['browser' => PantherTestCase::FIREFOX])
could be executed.
I thought maybe docker compose down
and docker compose up
could help (that maybe chrome driver created some state file which it checks upon phpunit startup), but this did not help.
So I tried installing xdebug to the container I was using - but after building the image with xdebug support enabled, the problem was gone and static::createPantherClient(['browser' => PantherTestCase::FIREFOX])
could be reached properly. So I probably wasn't that much far from the truth when trying the docker compose down/up
, but the docker cache invalidation caused by the xdebug install probably did something that made the problem go away.
I know it doesn't directly answer why the problem occurred in the first place, but at least it could be helpful when debugging various options for the static::createPantherClient()
method which are probably not considered at all once the problematic state file is created.
Same issue even with xdebug installed
Hello ! I got the same problem. Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming t hat Chrome has crashed.)
I'm trying to resolve it since two months and i nerver found a solution ........ !
With this : static::createPantherClient(['browser' => PantherTestCase::FIREFOX])
, firefox works well and i can run my tests
But if someone finds a way to make chromedriver works with Panther, i would be sooo happy to know how !
Hello!
I've been struggling to find a solution to this problem the last few days too. I found a workaround (more a workaround than a solution in my opinion, sorry 😞). Like the author of the issue, I was using alpine
as a source of my Dockerfile. I tried to use php
as a source (which uses Debian Buster as a source itself). And it works!
I also had to add these environment variables, otherwise the problem was still here:
ENV PANTHER_NO_SANDBOX 1
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage --disable-gpu --disable-extensions --remote-debugging-port=9222' # not sure all the arguments are needed here
My Dockerfile (still messy, sorry) is:
FROM php:8.0-fpm
RUN apt-get update; \
apt-get install -y --no-install-recommends \
coreutils \
make \
curl \
libcurl4-openssl-dev \
libxml2-dev \
zlib1g-dev \
libpng-dev \
libpq-dev \
libssl-dev \
libzip-dev \
libxslt1-dev \
bash \
git \
unzip \
chromium \
chromium-driver
RUN docker-php-ext-install \
gd \
intl \
opcache \
pdo_pgsql \
phar \
tokenizer \
zip \
xsl
RUN pecl install redis \
&& pecl install apcu \
&& pecl install xdebug \
&& docker-php-ext-enable \
redis \
apcu \
xdebug
RUN curl -sS https://getcomposer.org/installer | tee composer-setup.php \
&& php composer-setup.php && rm composer-setup.php* \
&& chmod +x composer.phar && mv composer.phar /usr/bin/composer
ENV PANTHER_NO_SANDBOX 1
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage --disable-gpu --disable-extensions --remote-debugging-port=9222'
CMD ["php-fpm"]
EXPOSE 9000
Run docker exec <your container name> ./vendor/bin/bdi detect drivers
and it will detect chrome. Hope this helps!
Hello
I don't understand why but today i send back "docker-compose build <container_name>" (same container config) and now phpunit not returns an error "DevToolsActivePort file doesn't exist". And the panther method "$client->takeScreenshot('screen.png')" save a screenshot file 👍 But no screenshot are automatically save on assert errors ?
I have succeed to install Panther with an other config (assert errors screenshots OK). Here is the detail of my 2 configs :
NOK (errors screenshots)
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.12.3
PHP 7.3.26 (cli) (built: Jan 7 2021 19:44:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.26, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.26, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
symfony/panther v1.0.1
OK
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.13.1
PRETTY_NAME="Alpine Linux v3.13"
PHP 7.4.14 (cli) (built: Jan 29 2021 01:54:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.4.5, Copyright (c) 2002-2020, by ionCube Ltd.
with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
Versions of chrome and chromedriver are the same on the 2 config as shown in my first post dockerfile are same on the 2 config :
RUN apk add --update --no-cache \
coreutils \
yarn \
unzip \
libzip-dev \
chromium \
chromium-chromedriver
# @see https://github.com/symfony/panther#docker-integration
ENV PANTHER_NO_SANDBOX 1
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage'
.env.test are same in the 2 config
I don't understand the fix of DevToolsActivePort and why I don't have automatic screeshots of errors ?
Hope this helps !
Same issue. I can't find a fix. Any one?
Ok, I found the problem. The ChromeManager service gets the variables using $ _SERVER [VARIABLE_NAME]. However, the environment variables defined in the Dockerfile are not in $ _SERVER. Therefore, the ChromeManager service is being created with invalid parameters. To solve this, the following arguments must be specified when creating the chrome client:
$client = Client::createChromeClient(null, [ '--headless', '--disable-dev-shm-usage', '--no-sandbox' ]);
I create a repository with a functional docker image: https://github.com/oscmarb/panther-chrome-client-docker
after listing 9515 port in the docker-compose-yml you need to add PANTHER_CHROME_ARGUMENTS="--disable-dev-shm-usage --disable-extensions --no-sandbox --whitelisted-ips=''"
but be careful
I faced with that error again, have a look please
root@3914903c22bc:/auth_service# /usr/lib/chromium/chromium --version
Chromium 90.0.4430.212
root@3914903c22bc:/auth_service# drivers/chromedriver --version
ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429})
and error
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
how to created client
$this->panterClient = static::createPantherClient([
'--remote-debugging-port=9222',
'--no-sandbox',
'--disable-dev-shm-usage',
'--headless'
], [], ['request_timeout_in_ms' => 20000000]);