Description
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.6.5
Rails version: Rails 6.1.4.1
RSpec version: rspec-core (3.10.1) and rspec-rails (5.0.2)
Observed behaviour
I'm trying to interact with the selenium driver to use the intercept
feature https://github.com/SeleniumHQ/selenium/blob/selenium-4.0.0/rb/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb#L63. I want to intercept all the requests done by the browser (my idea is to warn the users if the js code is doing any external request) so I'm trying to setup the intercept
in a before hook.
The problem is that page.driver
is a Capybara::RackTest::Driver in the before hook but it's a Capybara::Selenium::Driver during the actual example code, so I can't really interact with the example's driver before the test.
Expected behaviour
I would expect the before(:example) hook to have access to the same page.driver
of the example.
Can you provide an example app?
I don't have an example app, but it's pretty easy to reproduce. With an example that requires javascript (so the driver is not RackTest), run page.driver
in a before(:each)
block for that example and then run page.driver
when already in the example block. The first will show a:
EDIT: added a sample app to reproduce this, the README includes the instructions for the 3 methods I tried with RSpec and the config for Minitest too to compare https://github.com/arielj/HooksPageDriver/
Some debugging
I've been doing some debugging and I got to here https://github.com/rspec/rspec-core/blob/3-10-maintenance/lib/rspec/core/example.rb#L262. If I do @example_group_instance.page.driver
I get the RackTest driver, but when I step inside the next instruction (with step
in byebug) I'm taken directly inside the example bock, where I can run page.driver
to get the correct one.
I also tried with MiniTest and it works fine using an after_setup
hook, in that case page.driver
is the same driver the test uses.