testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Let selenium container have host network mode

Open parisni opened this issue 4 years ago • 1 comments

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.

parisni avatar May 09 '21 08:05 parisni

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

timbmg avatar May 13 '22 08:05 timbmg

Closing this for now. Feel free to get in touch if the issue persists. Thanks for the insights, @timbmg.

tillahoffmann avatar Jan 06 '23 20:01 tillahoffmann