webmock
webmock copied to clipboard
Probable incompatibility with Selenium?
Our test suite does not pass anymore since the release of the 3.16 version.
I found the culprit would be https://github.com/bblimke/webmock/pull/976
Our stack consist of :
- Ruby 3.1.2
- Rails 7.0.3.1
- VCR 6.1.0
- Selenium webdriver 4.3.0
- Capybara 3.37.1
Non-system tests pass as usual. On another app using the exact same stack but without system tests either (no Selenium/Capybara) we do not encounter problem either.
We have tried many different approaches to try to make tests pass:
- Webmock.enable! + Webmock.disable! # in setup/ teardown blocks
- WebMock.allow_net_connect!(net_http_connect_on_start: true)
- WebMock.allow_net_connect!(net_http_connect_on_start: [localhost]) # like exposed in #975
@bobmaerten thank you for reporting.
Can you please provide some more details? Does it raise any error and stacktrace? Are you able to provide an example that fails?
I was a little bit reluctant to create this issue, as we have very little context to provide. Our tests all fail with an error from Capybara returning page.current_path
as nil
but no further stack trace :'( . The tests are rather simple and were perfectly functional until v3.16. Here a sample of a failing test
def test_perform_visit
visit some_path
assert has_selector?(%(a.btn-primary[id="default-action"]))
assert has_selector?(%(a.btn-secondary[id="other-action"]))
find(%([id="other-action"]), match: :first).click
assert has_selector?(%(a.btn-primary[id="other-action"])) # Fails here after click involving a controller request
assert has_selector?(%(a.btn-secondary[id="default-action"]))
end
Minitest::UnexpectedError: NoMethodError: undefined method `map' for true:TrueClass
test/support/system/eshop/default_button_system_test:14:in `block in <class:DefaultButtonSystemTest>'
I found that my system tests do not run, and instead give me this error:
WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST http://127.0.0.1:9515/session with body '{"capabilities":{"alwaysMatch":{"browserName":"chrome","goog:chromeOptions":{}}}}' with headers {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'81', 'Content-Type'=>'application/json; charset=UTF-8', 'User-Agent'=>'selenium/4.9.1 (ruby macosx)'}
You can stub this request with the following snippet:
stub_request(:post, "http://127.0.0.1:9515/session").
with(
body: "{\"capabilities\":{\"alwaysMatch\":{\"browserName\":\"chrome\",\"goog:chromeOptions\":{}}}}",
headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Length'=>'81',
'Content-Type'=>'application/json; charset=UTF-8',
'User-Agent'=>'selenium/4.9.1 (ruby macosx)'
}).
to_return(status: 200, body: "", headers: {})
Removing require webmock/minitest
from my Rails application's test/test_helper.rb file causes the test to run just fine.
edit: Adding WebMock.disable_net_connect!(allow_localhost: true)
to my test also allows it to run without a problem. I'm not sure if this is the recommended solution.
I checked our test-suite against the latest version and it seems to work fine now. Can't tell what changed either on the gem side or from our tests ¯_(ツ)_/¯.
There were no WebMock version changes, therefore I expect that the issue was related to webmock in combination with something that has changed. Anyway, in case it happens again, please open the issue again.