LiveLoad.Browser.Connection defines a behaviour for how to connect to browsers with LiveLoad.
By default, an implementation for a Playwright instance (LiveLoad.Browser.Connection.Playwright)
is included in LiveLoad and can be looked at as reference implementation for implementing other browsers.
Summary
Callbacks
A hook called after the supervision tree for the browser is initialized in LiveLoad.Browser.start_link/2.
A hook called after the supervision tree for the browser is stopped in LiveLoad.Browser.stop/3
A hook called before the supervision tree for the browser is initialized in LiveLoad.Browser.start_link/2
A hook called before the supervision tree for the browser is stopped in LiveLoad.Browser.stop/3
Any connection can broadcast telemetry events that correspond to load test metrics which LiveLoad tracks during a scenario.
Since connections are generally modeled around Ports, the telemetry sent by those ports may be asynchronous in nature,
meaning that stopping a context does not necessarily mean that all metrics have completed sending and been consumed.
To avoid race conditions and dropping metrics, this callback can be implemented by a connection's metrics collection mechanism
to ensure that all metrics have been sent and drained.
Types
@type option() :: LiveLoad.Browser.Connection.Playwright.connection_option() | {atom(), term()}
@type opts() :: [option()]
@type t() :: module()
Any module implementing the LiveLoad.Browser.Connection behaviour.
Callbacks
@callback after_start(browser :: LiveLoad.Browser.t()) :: LiveLoad.Browser.t()
A hook called after the supervision tree for the browser is initialized in LiveLoad.Browser.start_link/2.
@callback after_stop(browser :: LiveLoad.Browser.t()) :: :ok
A hook called after the supervision tree for the browser is stopped in LiveLoad.Browser.stop/3
@callback before_start(browser :: LiveLoad.Browser.t()) :: LiveLoad.Browser.t()
A hook called before the supervision tree for the browser is initialized in LiveLoad.Browser.start_link/2
@callback before_stop(browser :: LiveLoad.Browser.t()) :: LiveLoad.Browser.t()
A hook called before the supervision tree for the browser is stopped in LiveLoad.Browser.stop/3
@callback child_spec(opts :: opts()) :: Supervisor.child_spec()
@callback drain_metrics(browser :: LiveLoad.Browser.t()) :: :ok
Any connection can broadcast telemetry events that correspond to load test metrics which LiveLoad tracks during a scenario.
Since connections are generally modeled around Ports, the telemetry sent by those ports may be asynchronous in nature,
meaning that stopping a context does not necessarily mean that all metrics have completed sending and been consumed.
To avoid race conditions and dropping metrics, this callback can be implemented by a connection's metrics collection mechanism
to ensure that all metrics have been sent and drained.
A reference implementation can be found in the LiveLoad.Browser.Connection.Playwright implementation of the connection behaviour.
@callback inner_html(context :: LiveLoad.Browser.Context.t(), selector :: String.t()) :: {:ok, {LiveLoad.Browser.Context.t(), String.t()}} | {:error, term()}
@callback new_context(browser :: LiveLoad.Browser.t()) :: {:ok, LiveLoad.Browser.Context.t()} | {:error, term()}
@callback page_content(context :: LiveLoad.Browser.Context.t()) :: {:ok, {LiveLoad.Browser.Context.t(), String.t()}} | {:error, term()}
@callback stop_context(context :: LiveLoad.Browser.Context.t()) :: :ok | {:error, term()}
@callback wait_for_selector( context :: LiveLoad.Browser.Context.t(), selector :: String.t() ) :: {:ok, LiveLoad.Browser.Context.t()} | {:error, term()}