'Selenium tests error: WebDriverError: unknown error: net::ERR_CONNECTION

I'm trying to run selenium tests but I get this error:

Error: WebDriverError: unknown error: net::ERR_CONNECTION_REFUSED
  (Session info: chrome=98.0.4758.102)
  (Driver info: chromedriver=98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758@{#972}),platform=Windows NT 10.0.19042 x86_64)
...
From: Task: WebDriver.navigate().to(https://localhost:4200/asd)

I tried to update webdriver but still not working. I really know what to do because I'm really new to Protractor etc. How can I solve this issue?



Solution 1:[1]

It looks like you are trying to send the browser to https://localhost:4200/asd. This is a URL that is passed to selenium. If you use Selenium Grid make sure that the URL can be reached from there. This especially means no localhost or 127.0.0.1 URLs, as they resolve to the selenium-grid-host.

If you need to detect the local network-IP you can try a variation of (node.js)

    var address,
      ifaces = require("os").networkInterfaces();
    for (const dev in ifaces) {
      ifaces[dev].forEach((details) => {
        if (details.family === "IPv4" && details.internal === false) {
          address = details.address;
        }
      });
    }

and build the URLs with the detected address.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TheConstructor