View Source ExMobileDevice.WebInspector (exmobiledevice v0.2.15)

Functions for controlling Mobile Safari.

This module provides a means of controlling Safari, without requiring SafariDriver. Starting an instance of this process will create a connection to an automated safari instance, on the specified device.

Example

iex(1)> alias ExMobileDevice.WebInspector
ExMobileDevice.WebInspector
iex(2)> {:ok, pid} = WebInspector.start_supervised("00008120-0018DEADC0DEFACE")
{:ok, #PID<0.208.0>}
iex(3)> {:ok, page} = WebInspector.create_page(pid)
{:ok, "page-7102B011-5BC0-4785-87DF-ADBA671EAD74"}
iex(4)> WebInspector.navigate_to(pid, page, "https://elixir-lang.org")
:ok

Summary

Functions

Returns a specification to start this module under a supervisor.

Close the specified page.

Create a new automation page.

Go to the previous url in the page's history.

Go to the next url in the page's history.

List the current automation pages.

Navigate the specified page to the provided url.

Reload the page's current url.

Transfer ownership to the specified process.

Create a supervised connection to the 'webinspector' service on the device.

Stop the webinspector process.

Switch to the specified page.

Take a screenshot of the current page, returning the bytes in PNG format.

Wait for the session to be created.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec close_page(:gen_statem.server_ref(), String.t()) :: :ok | {:error, any()}

Close the specified page.

@spec create_page(:gen_statem.server_ref()) :: {:ok, String.t()} | {:error, any()}

Create a new automation page.

@spec go_back(:gen_statem.server_ref(), String.t()) :: :ok | {:error, any()}

Go to the previous url in the page's history.

@spec go_forward(:gen_statem.server_ref(), String.t()) :: :ok | {:error, any()}

Go to the next url in the page's history.

@spec list_pages(:gen_statem.server_ref()) :: {:ok, [map()]} | {:error, any()}

List the current automation pages.

@spec reload(:gen_statem.server_ref(), String.t()) :: :ok | {:error, any()}

Reload the page's current url.

Link to this function

set_controlling_process(pid, cp)

View Source
@spec set_controlling_process(:gen_statem.server_ref(), pid()) ::
  :ok | {:error, any()}

Transfer ownership to the specified process.

Transfers controlling ownership of pid to cp. The caller must be the current owner.

@spec start_supervised(String.t()) :: DynamicSupervisor.on_start_child()

Create a supervised connection to the 'webinspector' service on the device.

The connection is supervised by an internal supervision tree of exmobiledevice. To manually stop the connection, call stop/1.

Controlling Process

On success, the caller is the 'controlling process' of the connection. Should the caller exit for any reason, the connection will also exit, which will in turn tear down the automation pages.

To transfer control to another process, call set_controlling_process/2.

@spec stop(pid()) :: :ok

Stop the webinspector process.

Stopping the process will terminate the connection to the webinspector service on the device, which will remove any automation pages from Safari.

Link to this function

switch_to_page(pid, page)

View Source
@spec switch_to_page(:gen_statem.server_ref(), String.t()) :: :ok | {:error, any()}

Switch to the specified page.

Link to this function

take_screenshot(pid, page)

View Source
@spec take_screenshot(:gen_statem.server_ref(), String.t()) ::
  {:ok, binary()} | {:error, any()}

Take a screenshot of the current page, returning the bytes in PNG format.

Link to this function

wait_for_session(pid, timeout \\ 5000)

View Source
@spec wait_for_session(pid(), non_neg_integer() | :infinity) ::
  :ok | {:error, :failed | :timeout}

Wait for the session to be created.