Network Request Spies¶
Network Request Spies inject hooks into the web browser to track activity.
The preferred usage is through the default instances on Page objects via the following attributes:
Page.fetch_spy
Page.xhr_spy
-
class
stere.browser_spy.
FetchSpy
¶ Spy for Fetch instances in the browser.
Allows scripts to block until network activity has stopped.
Example
>>> from stere.browser_spy import FetchSpy >>> >>> spy = FetchSpy() >>> spy.add() >>> # Browser interaction >>> spy.wait_for_no_activity() >>> # More browser interaction
Can also be used as a context manager, with add() called automatically:
Example
>>> from stere.browser_spy import FetchSpy >>> >>> with FetchSpy() as spy: >>> # Browser interaction >>> spy.wait_for_no_activity() >>> # More browser interaction
-
add
()¶ Inject the spy onto the page.
Tracks the active and total amount of requests.
-
wait_for_no_activity
()¶ Until timeout, keep checking if Fetch is done.
Requires the spy to already be present via FetchSpy.add()
Parameters: timeout (int) – Number of seconds to wait Raises: TimeoutError
-
active
¶ Get the number of active Fetch events.
-
total
¶ Get the number of total Fetch events.
-
-
class
stere.browser_spy.
XHRSpy
¶ Spy for XMLHttpRequest instances in the browser.
Allows scripts to block until network activity has stopped.
Example
>>> from stere.browser_spy import XHRSpy >>> >>> spy = XHRSpy() >>> spy.add() >>> # Browser interaction >>> spy.wait_for_no_activity() >>> # More browser interaction
Can also be used as a context manager, with add() called automatically:
Example
>>> from stere.browser_spy import XHRSpy >>> >>> with XHRSpy() as spy: >>> # Browser interaction >>> spy.wait_for_no_activity() >>> # More browser interaction
-
add
()¶ Inject the spy onto the page.
Tracks the active and total amount of requests.
-
wait_for_no_activity
()¶ Until timeout, keep checking if XHR is done.
Requires the spy to already be present via FetchSpy.add()
Parameters: timeout (int) – Number of seconds to wait Raises: TimeoutError
-
active
¶ Get the number of active XHR requests.
-
total
¶ Get the number of total XHR requests.
-