symfony / panther

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

Fresh google chroome faced with DevToolsActivePort file doesn't exist #505

Open shubaivanqbee opened 2 years ago

shubaivanqbee commented 2 years ago

I faced with that error again, have a look please

  "require-dev": {
    "dbrekelmans/bdi": "^0.3.0",
    "symfony/panther": "^1.1",
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',
            '--disable-gpu',
            '--disable-extensions',
        ], [], ['request_timeout_in_ms' => 20000000]);

my docker file

ENV PANTHER_NO_SANDBOX 1
# Not mandatory, but recommended
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage'
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/chrome.deb
RUN dpkg -i /tmp/chrome.deb || apt-get install -yf
RUN rm /tmp/chrome.deb
onadrog commented 2 years ago

Hi, I was facing the same problem, and after some research I found that. Docker doesn't had X server to display GUI that's why this error occurs. So I've downloaded the chromedriver from the website added it in my root project directory under the drivers folder and made some changes to the dockerfile and docker-compose here they are.

Dockerfile

ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage --no-sandbox --display=:0 --disable-gpu --disable-extensions --remote-debugging-port=9222'

You have to tell chrome what display to use here :0 (your host machine display) and in my docker-comopse file

docker-compse

services:
  phptest:
    //
    network_mode: host
    ports:
      - 9000:9000

So now you can change the PANTHER_NO_HEADLESS env to 1 if you want to see your chrome app.

You have to run xhost + in your terminal or it will not work.

As you can see it work like a charm (exepct for my tests ...):

https://user-images.githubusercontent.com/46002955/136551432-b0100ce8-4b2c-4009-b985-cb186afd86d3.mov

Hope it helps.

keldrox commented 2 years ago

@onadrog With your indications it works perfectly for me.

But chrome is terminated before pressing a key.

any solution?

Thank you!

onadrog commented 2 years ago

@keldrox sorry for the late response didn't see any mention in git,well. Check Interactive Mode section, but if chrome run and close automatically it means your tests pass. So add some errors in your test if you wan't to interact in chrome. In the video I've published it stopped because of an error.

jose-sampedro commented 2 years ago

I added error to make it stop, but it doesn't work

More information here https://github.com/symfony/panther/issues/515

floviolleau commented 2 years ago

Hi @onadrog,

I'm trying to do the exact same thing but I can't make it work. Can you please kindly add more details of your setup please?

Do I need to install chromedriver on the host? Is it normal that host + returns access control disabled, clients can connect from any host? xhost + needs to be ran in host ? container ? The test cli you are running is from the host? from the container? Defining ports and network_mode seems to not be compatible together in docker What is the purpose of opening 9000? Where port 9080 come from in your opened browser? Why downloading in the root project directory under the drivers folder the chromedriver? ...

Thanks for your help

adxl commented 2 years ago

@floviolleau did you find a way to make it work..?

floviolleau commented 2 years ago

Nope....

adxl commented 2 years ago

@floviolleau I finally managed to make it work, so I'll try to answer your questions, it could probably help you:

1 - yes you have to install chromedriver on your container because Panther launch it from there 2 - the return message for xhost + is okay, it means that it allow any connection (in this case the container can connect to your host) 3 - you have to run xhost + on the host so it can accept connections from your container 4 - I personally run my tests from the container 5 - making the network_mode: host will share the same ports between your host and the container, which means you don't have to specify ports explicitly. (I also added extra_hosts: - "host.docker.internal:127.0.0.1" while trying to solve the issue, but I haven't checked if it helps or not) 6 - for the ports it doesn't matter, as long as your container is running in a host network 7 - Panther will look for the driver in that folder, so it has to be there

I hope it helps

floviolleau commented 2 years ago

Thanks for the detailed answer!

I will give a new try in my next sprint.