3

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?

1
  • Which host OS are you using? Commented Oct 19, 2017 at 12:56

5 Answers 5

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

From the host machine, Docker endpoints aren't accessible at localhost. Did you try using 0.0.0.0 instead of 127.0.0.1?

1 Comment

I changed to usingServer('http://0.0.0.0:4444/wd/hub'). and the tests still don't run. I have a test that prints the body and it says "This site can’t be reached."
0

If you are using mac, you may try to get gateway from netstat inside docker image:

netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'

or write ifconfig from terminal, and get the inet address, try with that instead of 127.0.0.1.

Comments

0

What is docker ps command is returning for this container? Is it display like "0.0.0.0:4444->4444/tcp". ?

You can run sudo iptables -L -n and verify under "Chain DOCKER" section below line should come. ACCEPT tcp -- 0.0.0.0/0 x.x.x.x tcp dpt:4444

Comments

0

Just to make sure I understand - the selenium runs in the docker, and tries to access the node app that runs on the server?

In this case, these are two different "servers", so you need to use real IP addresses (or dns names)

pass the ip of the server as a parameter to the dockerized selenium image the simplest thing would probably be as an environment variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.