Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interacting with page.getBy*non-existing element hangs instead of throwing #7309

Open
6 tasks done
kettanaito opened this issue Jan 20, 2025 · 2 comments · May be fixed by #7312
Open
6 tasks done

Interacting with page.getBy*non-existing element hangs instead of throwing #7309

kettanaito opened this issue Jan 20, 2025 · 2 comments · May be fixed by #7312
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage

Comments

@kettanaito
Copy link
Contributor

Describe the bug

When using userEvent + page.getBy* and providing a selector that doesn't exist on the page, the test hangs forever instead of throwing "Element by this selector not found".

Reproduction

Reproduction repository: https://github.com/kettanaito/vitest-locator-issue

Actual behavior

 FAIL   chromium  src/App.test.tsx > fills in the email field
Error: Test timed out in 15000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".

System Info

System:
    OS: macOS 15.2
    CPU: (24) arm64 Apple M2 Ultra
    Memory: 90.80 GB / 128.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.0 - /usr/local/bin/node
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 9.15.3 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 132.0.6834.83
    Safari: 18.2
  npmPackages:
    vitest: ^3.0.2 => 3.0.2

Used Package Manager

npm

Validations

@kettanaito
Copy link
Contributor Author

In the light of actionTimeout change, I would strongly ask you to reconsider a better default. A test failing due to timeout and a test failing due to me trying to access an element that doesn't exist are two different debugging experiences. Perhaps, actionTimeout should be set to the suite's timeout and throw first, before the generic timeout error.

@kettanaito kettanaito linked a pull request Jan 20, 2025 that will close this issue
6 tasks
@hi-ogawa
Copy link
Contributor

I think this is important and playwright seems to deal with this dilemma somehow (assertion timeout vs. test timeout).

One idea I found in playwright is that, for the assertions expect.poll() and expect().toPass(), they adjust timeout dynamically based on remaining test time:

But, as seen in the above PR, they are technically bending a genuine test timeout by subtracting some magic value. One interesting artifact is that, this allows try/catch-ing "test" timeout error.

For their page API (e.g. page.waitForTimeout()) and locator timeout logic, I'm guessing they have a similar idea, but I couldn't figure it out yet.

@hi-ogawa hi-ogawa moved this to P2 - 3 in Team Board Jan 24, 2025
@hi-ogawa hi-ogawa added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage
Projects
Status: P2 - 3
Development

Successfully merging a pull request may close this issue.

2 participants