3
votes

I'm running automated tests using Ruby/Cucumber/Capybara/Chromedriver. The automated tests are running by jenkins. Strange thing is that sometimes the browser opens up, but with a black screen and i got Net::ReadTimeout, and the browser not closing, so taking up my Memory. What i would like to achieve is, that if this occurs the browser with black screen must be closed. Any suggestions? Here's the error i got in jenkins:

    Net::ReadTimeout (Net::ReadTimeout)
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:176:in `rbuf_fill'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:154:in `readuntil'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:164:in `readline'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http/response.rb:40:in `read_status_line'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http/response.rb:29:in `read_new'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1446:in `block in transport_request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `catch'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `transport_request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1416:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1409:in `block in request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:877:in `start'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1407:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/default.rb:124:in `response_for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/default.rb:78:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/common.rb:63:in `call'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:645:in `raw_execute'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:109:in `create_session'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:69:in `initialize'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/chrome/bridge.rb:42:in `initialize'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/driver.rb:61:in `new'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/driver.rb:61:in `for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver.rb:82:in `for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/capybara-2.11.0/lib/capybara/selenium/driver.rb:22:in `browser'
/var/lib/jenkins/workspace/autotest/features/support/env.rb:12:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/rb_support/rb_language.rb:96:in `load'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/rb_support/rb_language.rb:96:in `load_code_file'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:142:in `load_file'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:84:in `block in load_files!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:83:in `each'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:83:in `load_files!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime.rb:253:in `load_step_definitions'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime.rb:61:in `run!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/cli/main.rb:32:in `execute!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/bin/cucumber:8:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.4.0/bin/cucumber:22:in `load'
/var/lib/jenkins/.rbenv/versions/2.4.0/bin/cucumber:22:in `<main>'
1
make sure to start the selenium session only when the application is properly started.phoet
We are running into this same issue. On ubuntu 14.04 with all the dependencies installed and chrome can be started up in a terminal via xvfb. But when I start it up via ruby (selenium in our case) it just times out with the same stack trace in this question. So far have not found a solutionShyam Habarakada

1 Answers

0
votes

Trace where, exactly, this error is coming from in your code, then

begin
    <driver execution code>
rescue Net::ReadTimeout
    @driver.quit
end

This should catch the error and close the session as you desire.

What I've done, is write a separate method to handle errors

def rescue_exceptions
    begin
        yield
    rescue Selenium::WebDriver::Error::NoSuchElementError,
            Selenium::WebDriver::Error::UnknownError,
            Selenium::WebDriver::Error::StaleElementReferenceError,
            Selenium::WebDriver::Error::ElementNotInteractableError
        <Handle Errors Here>
    end
end

Then this method can be wrapped around other code that may cause issues

def SignIn
    rescue_exceptions {
        <Perform Actions Here>
    }
end