LiveLoad.Browser.Connection behaviour (LiveLoad v0.0.1-rc.18)

Copy Markdown View Source

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

Types

t()

Any module implementing the LiveLoad.Browser.Connection behaviour.

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

Different browser implementations may have different memory requirements, depending on how they are implemented. The LiveLoad.Cluster initialization procedure uses this callback in order to calculate the optimal amount of nodes to use for running a LiveLoad.Scenario based on the number of users for the test and the resources available on each cluster node.

Different browser implementations may have different memory requirements, depending on how they are implemented. The LiveLoad.Cluster initialization procedure uses this callback in order to calculate the optimal amount of nodes to use for running a LiveLoad.Scenario based on the number of users for the test and the resources available on each cluster node.

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

option()

opts()

@type opts() :: [option()]

t()

@type t() :: module()

Any module implementing the LiveLoad.Browser.Connection behaviour.

Callbacks

after_start(browser)

@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.

after_stop(browser)

@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

before_start(browser)

@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

before_stop(browser)

@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

browser_memory_usage_bytes()

@callback browser_memory_usage_bytes() :: pos_integer()

Different browser implementations may have different memory requirements, depending on how they are implemented. The LiveLoad.Cluster initialization procedure uses this callback in order to calculate the optimal amount of nodes to use for running a LiveLoad.Scenario based on the number of users for the test and the resources available on each cluster node.

child_spec(opts)

@callback child_spec(opts :: opts()) :: Supervisor.child_spec()

context_memory_usage_bytes()

@callback context_memory_usage_bytes() :: pos_integer()

Different browser implementations may have different memory requirements, depending on how they are implemented. The LiveLoad.Cluster initialization procedure uses this callback in order to calculate the optimal amount of nodes to use for running a LiveLoad.Scenario based on the number of users for the test and the resources available on each cluster node.

drain_metrics(browser)

@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.

inner_html(context, selector)

@callback inner_html(context :: LiveLoad.Browser.Context.t(), selector :: String.t()) ::
  {:ok, {LiveLoad.Browser.Context.t(), String.t()}} | {:error, term()}

navigate(context, url)

@callback navigate(context :: LiveLoad.Browser.Context.t(), url :: String.t() | URI.t()) ::
  {:ok, LiveLoad.Browser.Context.t()} | {:error, term()}

new_context(browser)

@callback new_context(browser :: LiveLoad.Browser.t()) ::
  {:ok, LiveLoad.Browser.Context.t()} | {:error, term()}

page_content(context)

@callback page_content(context :: LiveLoad.Browser.Context.t()) ::
  {:ok, {LiveLoad.Browser.Context.t(), String.t()}} | {:error, term()}

stop_context(context)

@callback stop_context(context :: LiveLoad.Browser.Context.t()) :: :ok | {:error, term()}

wait_for_selector(context, selector)

@callback wait_for_selector(
  context :: LiveLoad.Browser.Context.t(),
  selector :: String.t()
) ::
  {:ok, LiveLoad.Browser.Context.t()} | {:error, term()}