1

I have some system tests using Minitest/Capybara, but one part invariably fails when using NON-headless Chrome, even though it passes just fine when using the headless version.

This setup works:

# application_system_test_case.rb

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :headless_chrome
end

This causes the test to fail:

# application_system_test_case.rb

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium
end

The test in question checks the functionality of a certain Back button in my app (a custom button, not the browser default back button). The test finds and clicks the button, which calls history.back() internally. This is supposed to redirect the page back to the previous page, but instead, when using a NON-headless browser, it redirects to either the login screen or another unrelated screen. The final line in the snippet below fails.

page_before_settings_page = current_path
click_on 'Settings'
assert_current_path '/settings'

click_on 'Back'
assert_current_path page_before_settings_page

What baffles me even more is that there is a before_action filter for the login's controller, which is supposed to redirect you away from the login page if you're already logged in. So the login screen isn't even supposed to be accessible at that time. Sure enough, if I pause the test with a debugger after the login page is rendered and reload the page (visit current_path), the filter kicks in and redirects to the appropriate page. Any later requests to the login screen are redirected as well.

So my questions are:

  1. Is there a fundamental difference in how system tests are executed in headless vs non-headless Chrome browsers?

  2. This does not seem to be a race condition issue, since the redirect upon clicking the button is happening in time. It's the location to which the page gets redirected that's an issue. The Back button works perfectly fine when you actually use the app, so it seems to be an issue in system tests only. Any ideas as to why this may be occurring are appreciated.

reesaspieces
  • 1,600
  • 4
  • 18
  • 47

0 Answers0