Selenium WebDriver is getting Connection refused - Connection refused (Errno::ECONNREFUSED) - selenium

I am using Selenium WebDriver with Capybara for Cucumber features for parallel testing. But I am getting
Connection refused - Connection refused (Errno::ECONNREFUSED)
Is this error related to Selenium WebDriver? Is it a known issue with the driver? Is it something else?

That message indicates that the target host was unreachable, or was not listening for new connections.
I'd recommend verifying that the target can in fact be reached over the network (using curl, ping, tracert, or whatever tool you prefer), since the source of your problem is very likely external to your test code itself.

Related

I am getting following error "Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code." [duplicate]

Normally when I run chromedriver I always get this output which I'm sure everyone gets when running chromedriver. It's not the whole output but about a specif sentence.
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
As the title says and the output I always get. How do I make sure that the ports ChromeDriver is using only protected ports?
This INFO message...
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
... was the result of a bug which got induced with ChromeDriver v2.46
Analysis
As per the discussion 2.46 produces unexpected debug.log file if verbose logging is enabled, within the InitLogging() function of logging.cc some logging messages were written too early even before logging::InitLogging is called (at the last line of the function). This turned out to be OK on Linux and Mac OS, where the default log destination is where it is expected. But on Windows, the default log destination is a file named debug.log.
So ChromeDriver team needed to remove the two VLOG calls to the end of the method, after calling logging::InitLogging.
This issue was addressed through a commit and the fix was available within ChromeDriver 73.x
Protecting the ports that chromedriver use
There is nothing much we can do about the port usage as #barancev mentions ChromeDriver attempts to find a free Ephemeral port using a system-dependent ephemeral port range detector. An ephemeral port is a short-lived endpoint that is created by the operating system when a program requests any available user port. The operating system selects the port number from a predefined range, typically between 1024 and 65535, and releases the port after the related TCP connection terminates.
By default, the system can create a maximum of approximately 4,000 ephemeral ports that run concurrently on Windows Server 2003 and approximately 16,000 on Windows Server 2008.
Solution
Upgrading to ChromeDriver 73.x will solve this issue.
Outro
These log messages were the reflection of ChromeDriver - Security Considerations.
ChromeDriver is a powerful tool, and it can cause harms in the wrong hands. While using ChromeDriver, please follow these suggestions to help keeping it safe:
By default, ChromeDriver only allows local connections. If you need to connect to it from a remote host, use --whitelisted-ips switch on the command line to specify a list of IP addresses that are allowed to connect to ChromeDriver.
If possible, run ChromeDriver with a test account that has no access to sensitive local or network data. ChromeDriver should never be run with a privileged account.
If possible, run ChromeDriver in a protected environment such as Docker or virtual machine.
Use firewall to prevent unauthorized remote connection to ChromeDriver.
If you are using ChromeDriver through third-party tools such as Selenium Server, be sure to protect the network ports of those tools as well.
Use the latest versions of ChromeDriver and Chrome.
You can find the list of restricted ports on Chrome here.
I too had the same issue, all i did was add https to the link. eg:
driver.get("https://www.yahoo.com");
This solved the problem and my scripts are running.
This is just an informational message. Nothing to be worried about. Even I get the following message.
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103#{#416}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Let me breakdown the message and explain.
Part 1: Please protect ports used by ChromeDriver
This is applicable to any program. The ports need to be protected whereas outsiders are not allowed to access. Since you are using the default whitelisting in Chromedriver, you get the message Only local connections are allowed.
When you run this driver, it will enable your scripts to access this and run commands on Google Chrome.
This can be done via scripts running in the local network (Only local connections are allowed.) or via scripts running on outside networks (All remote connections are allowed.). It is always safer to use the Local Connection option. By default your Chromedriver is accessible via port 9515.
See this answer if you wish to allow all connections instead of just local.
Part 2: prevent access by malicious code
There are different kinds of scripts that check whether these ports are open. Since you have opened the Chromedriver only allowing local connections it is much safer, and you have to only worry about the scripts in your machine, that might try to hit the port of the Chromedriver.
But, if you had whitelisted IPs, other than the local connections, then you have to protect the ports using firewall rules, via the Cloud service provider or your Operating System.
For more information, please see the Security Configurations given be ChromeDriver.

Starting phantomjs node on Selenium grid on a external machine

I am trying to start a phantomjs node on a virtual machine to connect to my own computer which hosts the hub. I have gotten a generic node set up externally (5 instances of firefox, chrome and one instance of IE). When I try and set up a phantomjs node however, it registers fine from the command prompt, but when I go to the grid console, the following message is displayed:
DefaultRemoteProxy unknown version,Connect to failed: [myIp] Connection refused: connect
Does anyone have any experience with this?
Connection refused when phantomjs is run on different machine than selenium hub
Referenced this question... Basically had to add the IP of my node machine to the --webdriver param in the command line...

Teamcity - Selenium Grid environment - Unable to connect to the remote server

I am running a small selenium project using grid setup. All is fine when I run locally which has the hub and the node running in the same machine. What I did next was kept the hub running in my local machine and tried running the test through teamcity. I presume that the test will run in one of the build agents. When I kick start the build job, I got the following exception. Not sure what the issue is.
Test(s) failed. System.Net.WebException : Unable to connect to the remote server ---->
System.Net.Sockets.SocketException : A connection attempt failed because the connected
party did not properly respond after a period of time, or established connection failed
because connected host has failed to respond 192.168.6.121:80 at
System.Net.HttpWebRequest.GetResponse()
Also, the team city build agent IP is 192.168.7.132 whereas I am getting a message that it is unable to contact 192.168.6.121
Is there something happening which I am not aware of.
The selenium server is up and running in my local machine. and all is fine at the server end.
Any pointers will be much helpful

Unable to make web socket connection in Selenium opened googleChrome browser

Below is the test page to check the web socket connection, I am opening below page in selenium with (*googlechrome), i am unable to connect to the web sockets.
http://websocket.org/echo.html
However in normal googlechrome browser we are able to connect to the web socket.
What is the difference? appreciate your quick help..
~Ashok
Have you try to connect the web socket with other browser? I had the similar problem before but I was using Firefox, it turned out that the proxy setting wasn't get pass on to the firefox profile which selenium use.

Selenium Grid Error

Has anyone seen this error in CentOS, when running Selenium Grid:
SEVERE: Could not find any remote control providing the '*chrome' environment. Please make sure you started some remote controls which registered as offering this environment.
thanks!
I take it you started the hub but didn't start any nodes? You must start a node so it can run the RC Server needed to handle your client request.