I\'m trying to use selenium for the first time in a rails 3 app. (I\'ve used it before with rails 2). I\'m in an rvm which of course has its own gemset.
I first r
We use this to enable normal requests in capybara, and allow selenium's callbacks everywhere, because they are fired after requests are finished.
# spec/spec_helper.rb
RSpec.configure do |config|
config.before(:all, type: :request) do
WebMock.allow_net_connect!
end
config.after(:all, type: :request) do
selenium_requests = %r{/((__.+__)|(hub/session.*))$}
WebMock.disable_net_connect! :allow => selenium_requests
end
end
It's because you are using webmock. It blocks all outbound HTTP requests.
If you don't need it, remove it from the Gemfile. If you do need it, then you may need to configure it more precisely to your needs:
https://github.com/bblimke/webmock
To improve on @grosser code
RSpec.configure do |config|
config.before do
WebMock.enable!
if Capybara.current_driver != :rack_test
selenium_requests = %r{/((__.+__)|(hub/session.*))$}
WebMock.disable_net_connect! :allow => selenium_requests
WebMock.disable_net_connect! :allow => "127.0.0.1:#{Capybara.current_session.driver.server_port}" # this only works for capybara selenium and capybara-webkit
else
WebMock.disable_net_connect!
end
end
# for connections where we need to have network access we just tag it network
config.before(:each, :network => true) do
WebMock.disable!
end
end
With this...
WebMock.disable_net_connect!(:allow_localhost => true)
you allow real web access to your localhost. It's perfect when you need to use Selenium for you application and, at the same time, mock external resources.
Good suggestions here. Another, more fine-tuneable, solution:
WebMock.disable_net_connect!(
allow: [
'localhost',
'dynamo:8000',
'pact-broker:81'
]
)
Works especially well for whitelisting docker-compose containers!
In my specific case my problem was in evergreen (javascript rspec).
I added:
WebMock.disable_net_connect! :allow_localhost => true
To my environments/env*.rb because evergreen doesn't load rspec helpers.