Flaky Tests: Wait for the link URL field to take focus before typing by ellatrix · Pull Request #85996 · WordPress/gutenberg · GitHub
Skip to content

Flaky Tests: Wait for the link URL field to take focus before typing - #85996

Merged
ellatrix merged 1 commit into
trunkfrom
fix/e2e-links-wait-for-url-focus
Oct 30, 2026
Merged

ellatrix merged 1 commit into
trunkfrom
fix/e2e-links-wait-for-url-focus

Conversation

@ellatrix

Copy link
Copy Markdown
Member

What?

Three Links tests wait for the link popover's URL field to have focus before pressing keys, instead of only for the popover to be visible.

Why?

"Links › can be created by selecting text and using keyboard shortcuts" (Chromium) needed a retry in 3 of the last 7 trunk CI runs (2026-10-29). CI got content like This is h or This is https:// instead of This is Gutenberg: the start of the URL went into the paragraph and replaced the selected word.

  1. Cmd+K opens the link popover, and the test types the URL as soon as the popover is visible.
  2. The URL field takes focus later: useFocusOnMount() moves focus to the first input in a setTimeout.
  3. When the keys come first, they go to the paragraph. Logging where focus was when the popover became visible showed the paragraph in 3 of 8 runs, and the URL field in all 8 runs 500 ms later.

Locally it fails 16 of 20 times on trunk. (It fails just as often on the commit before "Rich Text: Register each field once instead of adding its own listeners" (#85887), after which CI started reporting it, so that change isn't the cause.)

The two "allows arrow keys to be pressed during link creation…" tests press keys right after the popover appears in the same way, and Escape can then miss the popover: they fail 6 of 20 times locally, though CI doesn't flag them.

How?

After checking the popover is visible, check that its "Search or type URL" field is focused, as other tests in this spec already do.

Testing Instructions

WP_BASE_URL=<site> npm run test:e2e -- --project=chromium --retries=0 --repeat-each=10 test/e2e/specs/editor/blocks/links.spec.js -g "allows arrow keys to be pressed during link creation|can be created by selecting text and using keyboard shortcuts"
  • Before: "can be created by selecting text…" failed 16 of 20; the arrow key tests 6 of 20.
  • After: 30 of 30 pass, and the whole links.spec.js passes (28).

There is no Playground link or screenshot: only e2e tests change.

Use of AI Tools

Investigated and written with Claude Code.

🤖 Generated with Claude Code

The URL field takes focus in a timeout after the link popover mounts,
so keys pressed as soon as the popover is visible could reach the
paragraph or the toolbar instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellatrix ellatrix added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.56 MB

156d479 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  getByRole('button', { name: 'Close' })
Expected: 2
Received: 1
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" getByRole('button', { name: 'Close' }) with timeout 5000ms
  - waiting for getByRole('button', { name: 'Close' })
    14 × locator resolved to 1 element
       - unexpected value "1"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:228:33
Undo restores the post selection when another synced entity is loaded in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 2,
+   "offset": 2,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeVisible() failed

Locator: getByRole('listbox', { name: 'Search results' })
Expected: visible
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeVisible" getByRole('listbox', { name: 'Search results' }) with timeout 5000ms
  - waiting for getByRole('listbox', { name: 'Search results' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:423:33)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:3
should only mutate text data on input in /test/e2e/specs/editor/various/rich-text.spec.js, passed after 1 failed attempt.
Error: locator.evaluate: Error: The selection change event listener was never called.
    at eval (eval at evaluate (:311:30), <anonymous>:6:15)
    at UtilityScript.evaluate (<anonymous>:313:16)
    at UtilityScript.<anonymous> (<anonymous>:1:44)
    at eval (eval at evaluate (:311:30), <anonymous>:6:15)
    at UtilityScript.evaluate (<anonymous>:313:16)
    at UtilityScript.<anonymous> (<anonymous>:1:44)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/rich-text.spec.js:407:42

156d479 Run

@ellatrix
ellatrix marked this pull request as ready for review October 30, 2026 02:39
@ellatrix
ellatrix merged commit f388316 into trunk Oct 30, 2026
101 checks passed
@ellatrix
ellatrix deleted the fix/e2e-links-wait-for-url-focus branch October 30, 2026 02:52
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant