Skip to content

Playwright: make waitForText with a CSS context match on innerText, like I.see - #5778

Merged
DenysKuchma merged 8 commits into
4.xfrom
copilot/fix-inconsistent-assert-behavior
Nov 9, 2026
Merged

DenysKuchma merged 8 commits into
4.xfrom
copilot/fix-inconsistent-assert-behavior

Conversation

Copilot AI commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

I.waitForText with a context compared text differently from I.see depending on the locator. For a CSS context it used Playwright's text= selector, which normalizes whitespace. For an XPath context (including anything built with .at(n)) it used innerText. The same text could therefore pass for I.see, fail for I.waitForText, and change result when .at(1) was added to the locator.

Changes

  • lib/helper/Playwright.js (waitForText):
    • The CSS-context branch no longer uses locator(${css} >> text=...).
    • It now resolves the elements with this._locate(locator) and reads innerText ?? textContent, the same extraction proceedSee uses.
    • It polls every 100 ms until waitTimeout and keeps the existing Text "..." was not found on page after N sec. error.
    • The XPath branch and the no-context branch are unchanged.
  • test/helper/webapi.js: adds a waitForText case using new Locator('#text').at(1) as the context.
I.waitForText('0 . 8 8', 1, '#app')            // CSS context, now matches innerText like I.see
I.waitForText('0 . 8 8', 1, locate('#app').at(1))  // XPath context, same result

Notes for review

  • I have not run the new test or the existing suite. Electron failed to install and no Playwright browsers are available in this environment, so this needs CI.
  • grabTextFrom is untouched and still returns textContent, so the \n 1\n 2\n 3\n result in the issue's first example persists. Switching it to innerText would change return values for existing users, so I left that for a separate decision.
  • The added test only covers the .at(1) path on /dynamic. It does not reproduce the span or Bootstrap scenarios from the issue.

Copilot AI linked an issue Oct 31, 2026 that may be closed by this pull request
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inconsistent assert behavior for text in tests Playwright: make waitForText with a CSS context match on innerText, like I.see Oct 31, 2026
Copilot AI requested a review from kobenguyent October 31, 2026 06:22
@kobenguyent
kobenguyent marked this pull request as ready for review November 1, 2026 05:47
@DenysKuchma

DenysKuchma commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

@kobenguyent Thanks! Approach is right, but two things before merge:

  1. The old code wrapped any failure into Text "..." was not found on page after N sec. - the new polling loop lets raw Playwright errors escape (detached context element, navigation mid-poll). Please wrap the loop so wait failures still produce the friendly message.
  2. Note the semantics change: unquoted text= was case-insensitive/whitespace-normalized, includes is case-sensitive on raw innerText. Intentional to match the XPath branch, but worth a line in the changelog.

Copilot AI and others added 6 commits November 9, 2026 16:57
- Wrap polling loop errors in friendly message to match old behavior
- Note: text= is now case-sensitive (was case-insensitive/whitespace-normalized)
  Intentional to match XPath branch semantics

Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
…:codeceptjs/CodeceptJS into copilot/fix-inconsistent-assert-behavior
@DenysKuchma
DenysKuchma merged commit 5ae0547 into 4.x Nov 9, 2026
16 checks passed
@DenysKuchma
DenysKuchma deleted the copilot/fix-inconsistent-assert-behavior branch November 9, 2026 17:20
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.

Inconsistent assert behavior for text

3 participants