Skip to content

Conversation

@dgozman
Copy link
Contributor

@dgozman dgozman commented Sep 1, 2025

This turns an error in the protocol into a successful call with the error message in the new errorMessage field. Existing "element(s) not found" error is migrated to this as well.

Note that expect protocol call may still throw for multiple reasons:

  • server connection dropped
  • failed to serialize expected/received value, e.g. in toHaveJSProperty()
  • unexpected playwright bug

Strict mode violation

Error: expect(locator).toHaveText(expected) failed

Locator: locator('div')
Expected string: "foo"
Error: strict mode violation: locator('div') resolved to 2 elements:
    1) <div>a</div> aka getByText('a')
    2) <div>b</div> aka getByText('b')

Call log:
  - Expect "toHaveText" with timeout 5000ms
  - waiting for locator('div')

Invalid selector

Error: expect(locator).toBeVisible() failed

Locator:  ##
Expected: visible
Error: Unexpected token "#" while parsing css selector "##". Did you mean to CSS.escape it?

Call log:
  - Expect "toBeVisible" with timeout 5000ms
  - waiting for ##

New look for "element(s) not found" error

Error: expect(locator).toBeVisible() failed

Locator:  locator('span')
Expected: visible
Error: element(s) not found
Timeout:  5000ms

Call log:
  - Expect "toBeVisible" with timeout 5000ms
  - waiting for locator('span')

@github-actions

This comment has been minimized.

@dgozman dgozman force-pushed the expect-no-throw-on-errors branch from 88c3179 to 507621c Compare September 1, 2025 10:55
@dgozman dgozman changed the title chore(expect): strict violations and invalid selectors are part of received chore(expect): explicit errorMessage Sep 1, 2025
@github-actions

This comment has been minimized.

@dgozman dgozman force-pushed the expect-no-throw-on-errors branch from 507621c to 22575f2 Compare September 1, 2025 13:07
@github-actions

This comment has been minimized.

This turns an error in the protocol in a successfull call with error
message in the new `errorMessage` field. Existing "element(s) not found"
error is migrated to this as well.

Note that expect protocol call may still throw for multiple reasons:
- server connection dropped
- failed to serialize expected/received value, e.g. in `toHaveJSProperty()`
- unexpected playwright bug

---

Strict mode violation

```
Error: expect(locator).toHaveText(expected) failed

Locator: locator('div')
Expected string: "foo"
Error: strict mode violation: locator('div') resolved to 2 elements:
    1) <div>a</div> aka getByText('a')
    2) <div>b</div> aka getByText('b')

Call log:
  - Expect "toHaveText" with timeout 5000ms
  - waiting for locator('div')
```

---

Invalid selector

```
Error: expect(locator).toBeVisible() failed

Locator:  ##
Expected: visible
Error: Unexpected token "#" while parsing css selector "##". Did you mean to CSS.escape it?

Call log:
  - Expect "toBeVisible" with timeout 5000ms
  - waiting for ##
```

---

New look for "element(s) not found" error

```
Error: expect(locator).toBeVisible() failed

Locator:  locator('span')
Expected: visible
Error: element(s) not found
Timeout:  5000ms

Call log:
  - Expect "toBeVisible" with timeout 5000ms
  - waiting for locator('span')
```
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Test results for "tests 1"

1 failed
❌ [playwright-test] › reporter-html.spec.ts:724 › merged › should warn user when viewing via file:// protocol @macos-latest-node18-2

2 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node18`

46752 passed, 819 skipped


Merge workflow run.

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.

2 participants