Problem/Motivation

Our current suite of phpunit tests are dated. We need to modernize them. We also should refactor them a bit so we can provide some code reuse with new Payment Element tests.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tomtech created an issue. See original summary.

  • 91bf40f9 committed on 2.x
    task: #3591766 Modernize the existing Card Element Tests
    
    By: tomtech
    
tomtech’s picture

Status: Active » Fixed

This overhauls the Stripe browser-based checkout test suite to be more reliable, faster, and easier to maintain. The core problem was that the old tests used sleep() calls and synchronous assertions that raced against Stripe's asynchronous iframe initialization, causing intermittent failures in CI. All test infrastructure has been consolidated into a new shared base class, and all PHP 8 attribute-based annotations have replaced legacy doc-comment annotations throughout.

Key improvements:

  • Eliminated sleep() and polling loops in favor of session->wait() with JS predicates, removing the largest source of flakiness.
  • Fixed cross-origin iframe key dispatch by switching to the W3C Actions API, which sends native keyboard events (isTrusted: true) rather than element-targeted postValue that ChromeDriver silently dropped.
  • Added Stripe readiness guards before entering each card iframe — tests now wait for StripeElement--empty and StripeElement--complete CSS classes set by Stripe's own JS, so keystrokes are never dispatched before Stripe's event listeners are attached.
  • Improved 3DS flow robustness with explicit frame-wait helpers, JS-dispatched button clicks (which headless Chrome doesn't drop), and a verified frame-exit check.
  • Added failure diagnostics via a tearDown() override that captures a screenshot and full HTML (including cross-origin iframe contents) on test failure.
  • Modernized all annotations from @group/@dataProvider doc-comments to #[Group]/#[DataProvider]/#[RunTestsInSeparateProcesses] PHP 8 attributes, and added void return types and explicit parameter types throughout.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.