mokr.waiters

Submodules

Classes

EventWaiter

Class to wait for an event to be emitted and then run a callback

NavigationWaiter

Class to listen to a mokr.frame.FrameManager for specific navigation

Package Contents

class mokr.waiters.EventWaiter(emitter: pyee.EventEmitter, event_name: str, predicate: Callable, timeout: float, loop: asyncio.AbstractEventLoop)

Class to wait for an event to be emitted and then run a callback predicate when it is. If the callback resolves to a truthy value, the timer is cancelled. Otherwise, a mokr.exceptions.MokrTimeoutError is raised.

Parameters:
  • emitter (EventEmitter) – Emitter to listen to.

  • event_name (str) – Event name to listen for.

  • predicate (Callable) – Callback to run when event is emitted.

  • timeout (float) – Time in milliseconds to wait for event.

  • loop (asyncio.AbstractEventLoop) – Running asyncio loop.

listener = None
promise
wait() Awaitable

Wait for the target event to be emitted and then run the target predicate when it is. If that resolves to a truthy value, cancel the timer, otherwise, raise a mokr.exceptions.MokrTimeoutError exception.

Returns:

Awaitable that yields result of the target callback.

Return type:

Awaitable

class mokr.waiters.NavigationWaiter(frame_manager: mokr.frame.FrameManager, frame: mokr.frame.Frame, timeout: int, wait_until: list[mokr.constants.LIFECYCLE_EVENTS] | mokr.constants.LIFECYCLE_EVENTS)

Class to listen to a mokr.frame.FrameManager for specific navigation event(s) (LIFECYCLE_EVENTS) in the target mokr.frame.Frame for up to a given timeout. If all events not seen before timeout, raises a MokrTimeoutError exception.

Parameters:
  • frame_manager (FrameManager) – The mokr.frame.FrameManager to watch for lifecycle events.

  • frame (Frame) – The mokr.frame.Frame that seen events count toward.

  • timeout (int) – Tiem in milliseconds to wait for event.

  • wait_until (list[LIFECYCLE_EVENTS] | LIFECYCLE_EVENTS) – Either a list of events or a single event to wait for.

navigation_promise() Any

Return the promise so errors can be handled externally.

Returns:

Navigation promise.

Return type:

Any

cancel() None

Stop this waiter, raise no errors.