Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect to a localhost site using Selenium Docker image?

I have a node application that I can start with node server.js and access on localhost:9000.

I have a series of e2e tests on selenium that run fine, but I am now looking to use the docker selenium image.

I start the docker image with docker run -d -p 4444:4444 selenium/standalone-chrome

and I changed my e2e test code to look like:

  var driver = new webdriver.Builder().
  usingServer('http://127.0.0.1:4444/wd/hub').
  withCapabilities(webdriver.Capabilities.chrome()).
  build();

  // driver.manage().window().setSize(1600, 1000);

  return driver.get('http://127.0.0.1:9000')
    .then(function() {
      // driver.executeScript('localStorage.clear();')
      return driver
    });

But selenium fails to connect to the app at all!

(If I uncomment the setSize line, the program fails right there)

I have the server up an running, and it's indeed accessible at localhost:9000. How can I get my test to properly use dockerized selenium, and properly point to a server on localhost?

like image 717
swagrov Avatar asked Dec 03 '25 21:12

swagrov


1 Answers

If you want your container network behaviour to be like your host machines use docker run --network=host

like image 122
herm Avatar answered Dec 05 '25 13:12

herm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!