Skip to content

Fix flakey cucumber specs#426

Open
cycomachead wants to merge 1 commit intomainfrom
cycomachead/ai/1/1
Open

Fix flakey cucumber specs#426
cycomachead wants to merge 1 commit intomainfrom
cycomachead/ai/1/1

Conversation

@cycomachead
Copy link
Copy Markdown
Member

Pivotal Tracker Link

What this PR does:

This pull request fixes flaky Cucumber/Capybara specs that were intermittently failing in CI due to race conditions between test steps and asynchronous JavaScript initialization.

How should this PR be tested?

  • Run the full Cucumber suite in CI (headless Chrome) and verify that previously flaky specs pass consistently across multiple runs.
  • Key scenarios to watch: email modal close, TinyMCE content fill/read, languages dropdown select/remove, CSV file attachment, and hidden element assertions.

Root causes addressed:

  • Slow JS initializationCapybara.default_max_wait_time bumped from 2s to 10s to give DataTables, TinyMCE, Selectize, and Bootstrap modals time to initialize under CI load.
  • Headless Chrome flags — Switched --headless to --headless=new; added --no-sandbox and --disable-dev-shm-usage for better CI resource handling.
  • Email modal close — Replaced fragile sleep 0.2 + click sequence with a direct Bootstrap $('#emailModal').modal('hide') API call, eliminating the race between required-field validation and the close button click.
  • TinyMCE race condition — Added a poll loop that waits for tinymce.editors.length > 0 before calling setContent, preventing undefined errors on async editor initialization.
  • Ambiguous Selectize lookups — Scoped languages dropdown steps to #teacher_languages by ID rather than first(".selectize-input"), which was matching the school selectize widget on the same form.
  • State leakage between scenarios — Wrapped Capybara.ignore_hidden_elements = false blocks in begin/ensure so a failing assertion can't leave the flag flipped and corrupt subsequent scenarios.

Are there any complications to deploying this?

No — test-only changes with no impact on application code.

Checklist:

  • Has this been deployed to a staging environment or reviewed by a customer?
  • Tag someone for code review (either a coach / team member)
  • I have renamed the branch to match PivotTracker's suggested one (necessary for BlueJay) (e.g. michael/12345-add-new-feature Any branch name will do as long as the story ID is there. You can use git checkout -b [new-branch-name])

Superconductor Ticket Implementation | App Preview | Guided Review

- Increase Capybara.default_max_wait_time to 10s to handle slow JS initialization.
- Update headless Chrome flags to use --headless=new and improve CI resource usage.
- Replace fragile sleep-based modal closing with direct Bootstrap API calls.
- Add polling for TinyMCE initialization to prevent race conditions.
- Scope Selectize lookups to specific IDs to avoid ambiguous matches.
- Use ensure blocks when toggling Capybara.ignore_hidden_elements to prevent state leakage between scenarios.

Co-authored-by: Claude Code <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.71%. Comparing base (daa7e96) to head (eb4769f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #426   +/-   ##
=======================================
  Coverage   74.71%   74.71%           
=======================================
  Files          29       29           
  Lines        1135     1135           
=======================================
  Hits          848      848           
  Misses        287      287           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant