Skip to content

Let selenium container have host network mode #143

Closed

Description

@parisni

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.

Activity

  1. timbmg commented on May 13, 2022

    @timbmg
    Contributor

    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
  2. tillahoffmann commented on Jan 6, 2023

    @tillahoffmann
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions