Search code examples
ruby-on-railsrspeccapybaraintegration-testingrspec-rails

Retrieve Params in Capybara Test


Is there a way to retrieve the submitted parameters in a capybara feature test?

The rspec test looks like that:

it 'can visit the next page' do
  visit root_path
  click 'form submit'

  # here I'd like to access the last request for debugging purposes
end

Normally I would not access the request at feature test level because of encapsulation. Is there a way to access it nevertheless?


Solution

  • While this is technically accessible when using the rack_test driver with Capybara (via page.driver.request) it is not recommended. It is not cross-driver and you're better off using byebug or just looking at logs to see what params were sent (as mentioned in the comments). It's not accessible in most drivers because the browser actually creates the request (when clicking a button/link, etc) and processes the response - Capybara doesn't know anything about it other than it clicked something.