3

I am trying to run an application which runs Selenium in order to take some screenshots.

When I am running the application in a docker compose file it all works fine, however, when I try to run in in a kubernetes cluster in the cloud I keep on getting the following message:Only local connections are allowed, and no connections seem to be established. To my mind the issue is due to networking and selenium does not allow connections which are not coming from localhost, as is the case in kubernetes.

I am using image: selenium/standalone-chrome image (selenium/standalone-chrome:3.141 in my chart), where apparently the chrome driver is: 2.43.600233

I have been trying to counter this with the --whitelisted-ips option, but to no avail. I have tried:

chromeOptions.addArguments("--whitelisted-ips");
chromeOptions.addArguments("--whitelisted-ips=");
chromeOptions.addArguments("--whitelisted-ips=''");

Here is some of my java code.

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.TakesScreenshot;
chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--verbose");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--whitelisted-ips=");
chromeOptions.addArguments("--disable-gpu");

Here is what I seen in the logs.

enter image description here

deann
  • 756
  • 9
  • 24
  • Is is only info message.More here: https://stackoverflow.com/questions/48547360/selenium-for-chromedriver-and-chrome-browser-and-the-log-message-only-local-con . – Peter1982 Jun 20 '19 at 22:16
  • @Peter1982 I do not really find an answer to my issue there. It explains thoroughly chrome versioning, and explains what the message means, but I do not get how to make my remote selenium pod listen to incoming connections from other pods. Also, I understand why there is a limitation, but that limitation should be lifted with the `--whitelisted-ips` flag – deann Jun 20 '19 at 22:22
  • What is you baseUrl in selenium test? Are you using local kubernetes IP addresses or you access to pod throught services? – Peter1982 Jun 21 '19 at 08:07
  • I am using services. I also tried installing selenium on an external for the cluster VM, used IP address there, and have the same issue. – deann Jun 21 '19 at 08:09
  • I a kind of hacked this around. It turned out that this `--whitelisted-ips=` option does not seem to be implemented in the [chromeOptions][1] yet. So, I change the command of the selenium container to: command: ["java"] args: ["-Dwebdriver.chrome.whitelistedIps=", "-Dwebdriver.chrome.driver=/usr/bin/chromedriver", "-jar", "/opt/selenium/selenium-server-standalone.jar"] .... [1]: https://peter.sh/experiments/chromium-command-line-switches/ – deann Jun 23 '19 at 00:50
  • ... I no longer get this message, but I still can not make it to work. The container connects makes a screenshot but does not send it back for some reason. So, I have another problem to solve .. – deann Jun 23 '19 at 00:52

1 Answers1

0

you need to setup whitelisted-ips argument for chromedriver executable. You can achive it by set env JAVA_OPTS for docker chrome-node image:

  chrome:
    image: selenium/node-chrome:3.141.59
    container_name: chrome
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
      - JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps=

fyi. chromeOptions.addArguments("--whitelisted-ips="); pass argument into chrome not chromedriver!

GetoX
  • 4,225
  • 2
  • 33
  • 30