1

Very new to Selenium testing and after reading the doc I tried to setup my own Selenium Grid Hub but I'm failing to use it for my local testing.

I setup the Selenium Grid Hub on a kubernetes cluster (following https://github.com/kubernetes/examples/tree/master/staging/selenium) and I manage to reach my nodes.

I've built a simple java application to test this is working as expected and I manage to reach web based url like http://www.google.com but I would like to be able to test my local app by using my RemoteWebDriver.

Here is what is actually working:

log.info("test selenium");
ChromeOptions chromeOptions = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://my-k8-node.com:32223/wd/hub"), chromeOptions);
driver.get("http://www.google.com");
String pageSource = driver.getPageSource();
log.info(pageSource);
driver.quit();

But I get a This site can't be reached - localhost refused to connect. with

driver.get("http://localhost:8080/health/check");

The same with

driver.get("http://host.docker.internal:8080/health/check");

Or with

driver.get("http://127.0.0.1:8080/health/check");

I didn't find any documentation on how to achieve this kind of setup but any hint is welcome.

I would like to further integrate the selenium testing to my Gitlab CI/CD so I should be able to run the test from a "local" point of view.

Thanks for reading.

MHogge
  • 5,408
  • 15
  • 61
  • 104
  • Sounds like you are running in Docker? If so, see this thread: https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container – pcalkins Apr 02 '20 at 18:13
  • 1
    Thanks for the link. But in my case I'm not running on the same machine. The "localhost" is referring to my computer. But maybe it's not possible to use a RemoteWebDriver in order to test localhost when both aren't on the same host machine. Then what could be the best practice to perform selenium testing on an application that is not exposed to the internet ? – MHogge Apr 03 '20 at 06:59
  • I know there is a way to pass local paths to remote drivers, but it seems doubtful that you could pass the localhost to it... why not run the tests on the local machine? – pcalkins Apr 03 '20 at 17:24
  • @MHogge Did you find any solution to this problem? because i am also looking for the solution as of yours. – Uday Oct 27 '20 at 06:28
  • Hi, what I was expecting was not possible because the remote server has no knowledge of my localhost so it couldn't make calls to it. I've created a test environment that is in the same cluster of my selenium server and I'm using the internal ip (10.x.x.x) of the app instead of localhost. You can also achieve this by installing selenium on your local machine. Hope this will help you. – MHogge Oct 27 '20 at 08:13

0 Answers0