While running automation tests I sometimes get a timeout error for Selenium Webdriver (I think this is where the issue is at least). Me and my team have all recently migrated to Macbooks (from a combination of Windows and Ubunutu machines) and are all getting this behaviour.
While running a suite of tests I will (seemingly at random) get the following error output in the console:
Errno::ETIMEDOUT: Failed to open TCP connection to 127.0.0.1:9515 (Operation timed out - connect(2) for "127.0.0.1" port 9515)
This doesn't happen consistently, sometimes I'll run a pack and not have any such errors, sometimes I'll have multiple occurrences.
Here is the code which registers the driver (in case anything here points to what the issue could be):
Capybara.register_driver :selenium do |app|
opts = Selenium::WebDriver::Chrome::Options.new
opts.add_argument '--start-maximized'
opts.add_argument 'disable-infobars'
opts.add_argument '--disable-notifications'
opts.add_preference(:safebrowsing,
enabled: true)
opts.add_preference(:browser, set_download_behavior: { behavior: 'allow' })
Capybara::Selenium::Driver.new(app, browser: :chrome, options: opts)
end
The gems I am using are Capybara (3.11.0), Cucumber (3.1.0) and Selenium-webdriver (3.141.0). I have ChromeDriver(73.0.3683.68) installed via HomeBrew
Has anyone encountered this issue and worked out what the cause is?
Port 9515 is the default port chromedriver runs on. If you happen to be using Chrome/chromedriver v74 try rolling back to 73 or forward to 75 - 74 has been reported to have issues where it will randomly hang.
Another potential solution is to upgrade to Capybara >= 3.16.0 which defaults to using a persistent connection to chromedriver. This would mean less opening/closing of connections and less chance for chromedriver to hang during connection establishment.
The code I'm using start the session doesn't seem to be working, but I don't know what is wrong with it.
I can create a session without logging in and do what I want but when I try to the use the recommended method of creating the driver with an Options object and adding a user-data-dir, I run into errors.
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data')
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.get("https://login.tripleseat.com/")
email_field = driver["login"]
email_field.send_keys("clshaps93#gmail.com")
email_field.submit
I want my program to get to the bottom section signed into my account without running into an error.
If I don't have a Chrome window already open, I end up with this error:
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:32:in initialize'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:inassert_ok': unknown error: cannot determine loading status (Selenium::WebDriver::Error::UnknownError)
from no such execution context
If I do have Chrome window already open, I end up with this error:
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:32:in initialize'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:inassert_ok': unknown error: Chrome failed to start: crashed (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Other values I have tried to use for user-data-dir just end up being ignored, in that a session starts without logging me in. Is there some code I need to add somewhere to avoid these errors?
I am trying to Launch chrome browser from Ruby Cucumber framework. But i see it is throwing me an error.
I followed the solutions from stack overflow i.e., to re install chrome application but i see it apparently not working for me.
Here is the code from env.rb file.
require 'selenium-webdriver'
Before do
Selenium::WebDriver::Chrome.driver_path="E:/chromedriver.exe"
$driver=Selenium::WebDriver.for(:chrome)
end
Error is see is as follows.
E:\Eclipse\LoginMercury>cucumber
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic
on/) to get coloured output on Windows
Feature: Registration and Login to Mercury Portal
Scenario: Registrating new user in Portal # features/Login.feature:3
unknown error: chrome failed to start
(Driver info: chromedriver=2.3,platform=Windows NT 6.1 x86) (Selenium::WebDr
iver::Error::UnknownError)
./features/support/env.rb:4:in `Before'
Given Load Home page # features/step_definitions/Log
inStep.rb:1
When User need provide Username and password # features/step_definitions/Log
inStep.rb:6
Then Login to Portal # features/step_definitions/Log
inStep.rb:10
Failing Scenarios:
cucumber features/Login.feature:3 # Scenario: Registrating new user in Portal
1 scenario (1 failed)
3 steps (3 skipped)
0m1.180s
As I am using Windows 7, I've tried with older versions of chrome driver even.(V2.3). Yet i failed.
Can someone help me in moving further.
Thanks...!!!!
This is an error when using an older version of the chrome driver such as your version 23 and the latest version of chrome browser.
Upgrade and replace the driver, that your automation path is using for it, to the latest version 27 and this will fix this error.
https://sites.google.com/a/chromium.org/chromedriver/downloads
Cheers.
I just use a watir script to download sequential status infos from a server. In most cases it works fine, but sometimes I get an Net::ReadTimeout error. I don't know why?
Code:
require "rubygems"
require "watir"
Watir.default_timeout = 180 # seconds – default is 60
prefs = { :download => { :prompt_for_download => false, :default_directory => path } }
browser = Watir::Browser.new :chrome, :switches => %w[--no-sandbox], :prefs => prefs
browser.goto 'https://www...'
...
Error Message:
/usr/lib/ruby/2.3.0/net/protocol.rb:158:in `rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)
from /usr/lib/ruby/2.3.0/net/protocol.rb:136:in `readuntil'
from /usr/lib/ruby/2.3.0/net/protocol.rb:146:in `readline'
from /usr/lib/ruby/2.3.0/net/http/response.rb:40:in `read_status_line'
from /usr/lib/ruby/2.3.0/net/http/response.rb:29:in `read_new'
from /usr/lib/ruby/2.3.0/net/http.rb:1437:in `block in transport_request'
from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `catch'
from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `transport_request'from /usr/lib/ruby/2.3.0/net/http.rb:1407:in `request'
from /usr/lib/ruby/2.3.0/net/http.rb:1400:in `block in request'
from /usr/lib/ruby/2.3.0/net/http.rb:853:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:57:in `request'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in `raw_execute'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:124:in `create_session'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:88:in `initialize'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/chrome/bridge.rb:41:in `initialize'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `new'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `for'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver.rb:82:in `for'
from /var/lib/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:46:in `initialize'
from /var/www/jobs/ubuntu.rb:110:in `new'from /var/www/jobs/ubuntu.rb:5:in `<main>'
I just looking for a reason on this?
Is it possible the customize the settings on firefox? What is wrong?
Watir Version: 6.0.2
Selenium Version: 3.0.1
Browser Chrome Version: 57.0.2987.110
Chrome Driver Version: 2.29.461571
OS Version: Ubuntu 16.04.3 LTS
I had a similar problem when running my Selenium Webdriver tests on our Ubuntu Jenkins build server, but I never experienced this locally on my Windows PC. Like your problem, it was an intermittent issue. I spent quite a lot of time researching it and couldn't get to the bottom of it, I did however put it down to a Ruby/ Ubuntu issue rather than an issue with the test, because of this, I decided to rescue the Net::ReadTimeout error and retry. Since implementing the following example, I haven't experienced this problem again.
attempts = 0 # has to be outside the begin/rescue to avoid infinite loop
begin
profile = Selenium::WebDriver::Chrome::Profile.new
$driver = Selenium::WebDriver.for :chrome, :profile => profile,
$driver.manage.window.resize_to(1280, 720)
rescue Net::ReadTimeout => e
if attempts == 0
attempts += 1
retry
else
raise
end
end
You should be able to briefly modify the above example to work with Watir. It basically captures the error and retries/ re-runs the test.
First of all, Watir.default_timeout has nothing to do with error you have stated, So even if you increase the time of default_timeout, nothing would happen in this place, Watir.default_timeout is applicable only when you find an element, not for page_load.
Second off, this problem only exist in Ruby Selenium Binding, not in Java Selenium Binding, for an example, If you set
driver.manage.timeouts.page_load=120 (WATIR doesn't provide any systax to this selenium equivalent, so to write this code in WATIR, please invoke b.driver.)
This time settings is only applicable for goto method, it's not affecting anything when you click a button and waiting for a page load, the default timeout for page_load is 60 seconds, that would anyhow wait for 60 seconds, but what you set doesn't affect or change this 60 seconds. But this problem is not there for Selenium Java Binding, it's working properly.
Okay, the question is, you are using it for goto so why not you can use the page_load to set the time?
Actually you can decrease the time, but you can't increase the time beyond 60 seconds. But I found some workaround for this problem, but I strongly recommend you to file a bug in ruby selenium binding.
So it's not a WATIR problem, it's the problem in Ruby selenium binding.
Finally i tested also the solution with firefox and get the described error:
/var/lib/gems/2.1.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/response.rb:69:in 'assert_ok':
TypeError: Given platformVersion [object String] "any", but current platform version is [object String] "3.16.0-4-amd64"
(Selenium::WebDriver::Error::SessionNotCreatedError)
It seems to be a problem with a specific firefox and geckodriver version. I tested many combinations. This versions work without the TypeError:
Firefox 51.0.1
geckodriver 0.11.1
Thanks to dan.brown
unable to execute the ruby Watir script, empty browser instance is opened and the below error is thrown.
ERROR:
C:\watir>ruby DevStageCompareNew.rb
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:878:in
initialize: No connection could be made because the target machine actively refused it. - connect(2) (Errno::
ECONNREFUSED)
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:878:in open
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:878:in block in connect
from C:/Ruby200-x64/lib/ruby/2.0.0/timeout.rb:52:in timeout
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:877:in connect
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:862:in do_start
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:851:in start
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1367:in request
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/default.rb:83:in response_for
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/default.rb:39:in request
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/common.rb:40:in call
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:640:in raw_execute
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:101:in create_session
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:68:in initialize
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/bridge.rb:29:in initialize
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in new
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in for
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver.rb:67:in for
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.7.0/lib/watir-webdriver/browser.rb:46:in initialize
from DevStageCompareNew.rb:4:in new
from DevStageCompareNew.rb:4:in <main>
can someone help to resolve this..