.focus()
is not implemented like other action commands, and does not follow
the same rules of
waiting for actionability
.
.focus()
is a helpful command used as a shortcut. Normally there's no way for
a user to "focus" an element without causing another action or side effect.
Typically the user would have to click or tab to this element.
Oftentimes using
.focus()
directly is more concise and conveys what you're
trying to test.
If you want the other guarantees of waiting for an element to become actionable,
you should use a different command like
.click()
.
Can time out because your browser did not receive any focus events
If you see this error, you may want to ensure that the main browser window is
currently focused. This means not being focused in debugger or any other window
when the command is run.
Internally Cypress does account for this, and will polyfill the blur events when
necessary to replicate what the browser does. Unfortunately the browser will
still behave differently when not in focus - for instance it may throttle async
events. Your best bet here is to keep Cypress focused when working on a test.