Reputation: 375
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].
743 examples, 0 failures, 30 pending
/builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.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://selenium__standalone-chrome:4444/wd/hub/session/0146cfc5158d585f445cfcdbda289733
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:
...................................................................................................................................................................................................................................................................... ............................................................................................................................................................................................................................... .....................................................................................................................................................................................**...**............................................******
In spec/support/capybara.rb I have allowed connections to any URL with selenium, or session in it:
selenium_session_requests = %r{/((__.+__)|(hub/session.*))$}
allowed_connections = [
'0.0.0.0', '127.0.0.1', 'https://chromedriver.storage.googleapis.com',
'localhost', /selenium/, selenium_session_requests
].freeze
RSpec.configure do |config|
config.before(:suite) do
WebMock.enable!
end
config.after(:suite) do
WebMock.disable!
end
Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}"
Capybara.javascript_driver = ENV.fetch('CAPYBARA_JAVASCRIPT_DRIVER', :chrome_headless).to_sym
WebMock.disable_net_connect!(allow: allowed_connections, net_http_connect_on_start: allowed_connections)
end
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.
WebMock does not allow the Selenium driver to exit the browser.
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:
image: ruby:2.6
services:
- postgres:10.1
- selenium/standalone-chrome:latest
- redis:latest
The URL for that service is exposed to my specs via an environment variable:
- export SELENIUM_REMOTE_URL="http://selenium__standalone-chrome:4444/wd/hub"
[2] Here is the full output from the WebMock error:
/builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.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://selenium__standalone-chrome:4444/wd/hub/session/0146cfc5158d585f445cfcdbda289733 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.1.0 (ruby linux)'} (WebMock::NetConnectNotAllowedError) You can stub this request with the following snippet: stub_request(:delete, "http://selenium__standalone-chrome:4444/wd/hub/session/0146cfc5158d585f445cfcdbda289733"). 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.1.0 (ruby linux)' }). to_return(status: 200, body: "", headers: {}) ============================================================ from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/http/default.rb:124:in
response_for' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/http/default.rb:77:inrequest' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/http/common.rb:59:in
call' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/bridge.rb:588:inexecute' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/bridge.rb:188:in
quit' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/driver.rb:181:inquit' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/selenium/driver.rb:293:in
quit' from /builds/abelsoninfo/aws/pips/pips-console/vendor/ruby/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/selenium/driver.rb:512:in `block in setup_exit_handler'
Upvotes: 1
Views: 258