testcontainers-python
testcontainers-python copied to clipboard
Let selenium container have host network mode
So far, the selenium driver cannot access localhost based website since it is running inside it's docker container network.
One have to provide the host IP in order to give it access to local website, local api, and so on.
It would ease setup to provide an option to make the BrowserWebDriverContainer have host network.
That should work already. The BrowserWebDriverContainer passes a kwargs object down to the DockerContainer constructor. When we call the start function, that kwargs object is passed to container.run. And according to the docker-py documentation you can pass network as a parameter. So just pass network="host" to the BrowserWebDriverContainer construtor, or any instance of DockerContainer for that matter.
from selenium.webdriver import DesiredCapabilities
from testcontainers.selenium import BrowserWebDriverContainer
with BrowserWebDriverContainer(capabilities=DesiredCapabilities.CHROME, network="host"):
# here DockerContainer.start is called via __enter__
pass
Closing this for now. Feel free to get in touch if the issue persists. Thanks for the insights, @timbmg.