Open james-ai opened 1 year ago
@james-ai did you find a solution to this?
@madleech unfortunately not, and I haven't been given time to look into it in a while. Are you experiencing the same issue?
@madleech what is the method and host that WebMock is blocking for you? What parameters have you passed to disable_net_connect!
?
@madleech unfortunately not, and I haven't been given time to look into it in a while. Are you experiencing the same issue?
@james-ai I am. I worked around it by adding:
# Add hook to allow capybara to cleaning terminate selenium session
RSpec.configure do |config|
config.after(:suite) do
WebMock.allow_net_connect!
end
end
@madleech what is the method and host that WebMock is blocking for you? What parameters have you passed to
disable_net_connect!
?
@bblimke The error I'm getting is:
Traceback (most recent call last):
8: from /app/vendor/bundle/ruby/2.7.0/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:519:in `block in setup_exit_handler'
7: from /app/vendor/bundle/ruby/2.7.0/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:293:in `quit'
6: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/common/driver.rb:173:in `quit'
5: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/remote/bridge.rb:187:in `quit'
4: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/remote/bridge.rb:619:in `execute'
3: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
2: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/remote/http/default.rb:77:in `request'
1: from /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.9.0/lib/selenium/webdriver/remote/http/default.rb:119:in `response_for'
/app/vendor/bundle/ruby/2.7.0/gems/webmock-3.18.1/lib/webmock/http_lib_adapters/net_http.rb:104:in `request': Real HTTP connections are disabled. Unregistered request: DELETE http://127.0.0.1:9515/session/e5ff6c4369da9f8ef8e81c2779191152 with headers {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json; charset=UTF-8', 'User-Agent'=>'selenium/4.9.0 (ruby linux)'} (WebMock::NetConnectNotAllowedError)
You can stub this request with the following snippet:
stub_request(:delete, "http://127.0.0.1:9515/session/e5ff6c4369da9f8ef8e81c2779191152").
with(
headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json; charset=UTF-8',
'User-Agent'=>'selenium/4.9.0 (ruby linux)'
}).
to_return(status: 200, body: "", headers: {})
I'm using this in my rails_helper
:
WebMock.disable_net_connect!(allow_localhost: true, allow: ['datadog-agent'])
On a suspicion I searched the codebase for other WebMock.disable_net_connect!
and found a couple of parameter-less examples burried in the middle of someone's spec. They're obviously overwriting the original disable_net_connect!
call hence the selenium errors.
Sigh! So @james-ai maybe check to see if there are any hidden disable_net_connect!
calls in your specs?
Apologies if this is the wrong place to post this. Having an issue where it seems that webmock is stopping the capybara selenium driver from deleting the session. Details below.
System
Summary
Whilst successfully running a suite of tests on GitLab CI[1], WebMock intercepts a request from Capybara's Selenium driver to delete a session[2].
Although the error appears after the tests have run I wonder if it occurs whilst the specs are running? This is due to seeing newlines appearing in the RSpec output on GitLab, but not when run locally:
In spec/support/capybara.rb I have allowed connections to any URL with selenium, or session in it:
I have previously confirmed in the
before(:suite)
block that a session URL, such as http://selenium__standalone-chrome:4444/wd/hub/session/0146cfc5158d585f445cfcdbda289733, would be allowed by WebMock.Per the suggestion in [2] I stubbed the request - though I don't believe this is desired behaviour - but that still caused the same error.
Observed behaviour
WebMock does not allow the Selenium delete the session and complete the browser exit.
Desired behaviour
The session is deleted, the browser is closed, and no errors are raised.
[1] In .gitlab-ci.yml I have a docker service to enable the use of Selenium:
The URL for that service is exposed to my specs via an environment variable:
[2] Here is the full output from the WebMock error: