Fix flaky system tests: wait for Turbo redirect before asserting content#80
Merged
HamptonMakes merged 1 commit intomainfrom Apr 3, 2026
Merged
Fix flaky system tests: wait for Turbo redirect before asserting content#80HamptonMakes merged 1 commit intomainfrom
HamptonMakes merged 1 commit intomainfrom
Conversation
After clicking 'Sign In', Turbo Drive replaces the page body via a
redirect to the plans index. If Selenium asserts have_content('Sign out')
before the navigation completes, it references a stale DOM node from the
sign-in page, causing 'Node with given id does not belong to the document'.
Fix: add have_current_path(root_path) after click_button to wait for the
redirect to complete before asserting on the new page's content. Applied
to all three system spec files that share this sign-in pattern.
Amp-Thread-ID: https://ampcode.com/threads/T-019d5520-a72e-723a-9dc4-7ee62fb4fb5d
Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
System tests intermittently fail with
Node with given id does not belong to the documentduringsign_in(e.g.,comment_ux_spec.rb:596). This is a Selenium race condition: afterclick_button 'Sign In', Turbo Drive replaces the page body via a redirect to the plans index. Ifhave_content('Sign out')is evaluated before the navigation completes, Selenium references a stale DOM node from the sign-in page.Fix
Add
expect(page).to have_current_path(root_path)afterclick_buttonto wait for the Turbo redirect to complete before asserting on the new page's content. This is standard Capybara best practice for form submissions that trigger page navigations.Applied to all three system spec files sharing this sign-in pattern:
spec/system/comment_ux_spec.rbspec/system/comment_anchoring_spec.rbspec/system/tokens_spec.rbVerification
All 40 system specs pass locally.