Rayrun
← Back to Discord Forum

how not to throw exception on timeout?

Is it possible to not throw an exception on timeouts? This is slightly inconvenient when attempting to wait for a navigation OR an element to show, and do something based on which happens, wrapped in a try catch and it still breaking on the exception. I understand that I can exclude it, but there must be a real solution?

This thread is trying to answer question "How can one handle timeouts in asynchronous operations without throwing exceptions?"

2 replies

properly handling the exception would be better a better way to ask

I assume you mean the timeout of an action not the overall test timeout (default 30s)? In some cases i attached .catch(() => {/.../}) on promises to ignore or handle failures. Only the initial action that threw the error will be marked failed in the report. The test itself will still pass for errors that were handled by catch.

Maybe you are looking for something like Promise.race: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].