allwright

API ReferencePythonHooks

Hooks

A hook coordinates a browser-native event that fires asynchronously outside any direct call — a new tab, a native file picker, a download. register_hook before the triggering action, then wait for it, so the event can't be missed between the two.

hooks.new_page

PropertySince v0.1.5

Waits for a tab opened by the triggering action. Registers on the page that triggers the event (not the browser) as of v0.1.6, which fixed misattribution when more than one tab could plausibly open around the same time.

hooks.new_page: HookType[Page]

Example

from allwright import hooks
hook = page.register_hook(hooks.new_page)
page.click("a[target=_blank]")
new_page = hook.wait()

hooks.file_chooser

PropertySince v0.1.7

Waits for the native file-picker dialog; no OS dialog actually renders. The resulting FileChooser's set_files(...) supplies one or more paths.

hooks.file_chooser: HookType[FileChooser]

Example

hook = page.register_hook(hooks.file_chooser)
page.click("button.open-upload")
chooser = hook.wait()
chooser.set_files("fixtures/document.pdf")

hooks.download

PropertySince v0.1.7

Resolves as soon as a download starts, exposing url and suggested_filename immediately. The resulting Download's save_as(path) waits for it to finish and copies it to path.

hooks.download: HookType[Download]

Example

hook = page.register_hook(hooks.download)
page.click("a.download-report")
download = hook.wait()
download.save_as(f"artifacts/{download.suggested_filename}")