Home > other >  Selenium in a docker can't perform actions on my frontend in localhost
Selenium in a docker can't perform actions on my frontend in localhost

Time:10-25

I'm working on Selenium testing.
I'm trying to encapsulate all the tests in a docker container.
The tests communicate with the frontend to make some actions (i mean to test them).

Selenium runned tests are in a docker container.
Frontend is running on localhost (not in a docker).

In my Selenium docker I specified the url of the frontend with the ip of the host: 172.17.0.1, I even tried to use "host.docker.internal", but it's not working at all.
However if I run the container manually and do a "curl http://172.17.0.1:{FRONTEND_PORT}" I receive a response!
Meaning the docker can actually communicate with the frontend.
But with Selenium tests it's not working...

Do you have an idea how to resolve the issue?

EDIT:

ifconfig output in my docker:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 97  bytes 259089 (253.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 65  bytes 4469 (4.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

CodePudding user response:

OK! I found the answer!

As a reminder: Selenium tests in a container. Frontend in localhost.

As it's the WebDriver that performs actions on the frontend then the calls made by the frontend come from the network of the selenium container!

In my case: the frontend was cally the backend on this url http://localhost:8080/myrequestothebackend

BUT as the chromedriver made requests from the selenium container then the frontend calls didn't worked because it was targeting the localhost of the selenium container (and not the 'real' localhost of the computer!)

  • Related