Fix flaky feature tests in headless chrome
What does this MR do and why?
Fix flaky feature tests in headless chrome
This change adds the disable-backgrounding-occluded-windows flag when on
headless chrome as it prevented tests that used animated elements, such
as modals and toasts, from running correctly.
This change fixes issues for users running tests locally against GDK but it may prevent flakiness in other environments where headless Chrome is used.
Why is this important?
This seems to impact browser tests when using headless Chrome.
I am mostly concerned with this problem spreading to more environments and browser versions as such optimizations a undertaken by more versions of Chrome and possible other webkit browsers.
Why does it work?
Chrome seems to have added some optimizations to headless mode that prevent it from running callbacks of requestAnimationFrame.
This resulted in some feature/ tests failing when running locally. For example, when running two tests for running deletion that depended on confirmation modals, the second test failed with Unable to find visible css "[role=\"dialog\"]".
bundle exec rspec -f d spec/features/admin/runners/admin_manages_runners_spec.rb:30:35
![]() |
The cause of the failure was not obvious in the screenshot, but it appeared in the HTML snapshot, as the dialog was not made visible.
| html (class="modal fade gl-block gl-modal") | png |
|---|---|
![]() |
![]() |
The failing test depends on requestAnimationFrame completing to display the modal, and as Chrome skipped the callbacks (#536663 (comment 2530821119)) the tests failed.
After adding these flags tests can run normally in my local, and it should improve compatibility in situations where headless chrome is used.
References
- https://github.com/teamcapybara/capybara/issues/2796#issuecomment-2678172710
- Find and fix root cause of flakiness in local E... (#536663 - closed)
Screenshots or screen recordings
NA
How to set up and validate locally
Run a test suite that depends on animated elements, like modals or toasts. I happen to maintain this one:
bundle exec rspec -f d spec/features/admin/runners/admin_manages_runners_spec.rb
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #536663 (closed)


