wallaby v0.14.0 Wallaby.Session

Common functionality for interacting with Sessions.

Sessions are used to represent a user navigating through and interacting with different pages.

Fields

  • id - The session id generated from the webdriver
  • session_url - The base url for the application under test.
  • server - The specific webdriver server that the session is running in.

Multiple sessions

Each session runs in its own browser so that each test runs in isolation. Because of this isolation multiple sessions can be created for a test:

test "That multiple sessions work" do
  {:ok, user1} = Wallaby.start_session
  user1
  |> visit("/page.html")
  |> fill_in("Share Message", with: "Hello there!")
  |> click_button("Share")

  {:ok, user2} = Wallaby.start_session
  user2
  |> visit("/page.html")
  |> fill_in("Share Message", with: "Hello yourself")
  |> click_button("Share")

  assert user1 |> find(".messages") |> List.last |> text == "Hello yourself"
  assert user2 |> find(".messages") |> List.first |> text == "Hello there"
end

Summary

Functions

Deletes a session

Executes javascript synchoronously, taking as arguments the script to execute, and optionally a list of arguments available in the script via arguments

Gets the current path of the session

Gets the current url of the session

Gets the size of the session’s window

Retrieves the source of the current page

Gets the title for the current page

Sends a list of key strokes to active element. Keys should be provided as a list of atoms, which are automatically converted into the corresponding key codes

Sends text characters to the active element

Sets the size of the sessions window

Takes a screenshot of the current window. Screenshots are saved to a “screenshots” directory in the same directory the tests are run in

Changes the current page to the provided route. Relative paths are appended to the provided base_url. Absolute paths do not use the base_url

Types

t :: %Wallaby.Session{id: integer, screenshots: list, server: pid, session_url: String.t, url: String.t}

Functions

delete(session)

Specs

delete(t) :: :ok

Deletes a session.

execute_script(session, script, arguments \\ [])

Specs

execute_script(t, String.t, list) :: t

Executes javascript synchoronously, taking as arguments the script to execute, and optionally a list of arguments available in the script via arguments

get_current_path(session)

Specs

get_current_path(t) :: String.t

Gets the current path of the session

get_current_url(session)

Specs

get_current_url(t) :: String.t

Gets the current url of the session

get_window_size(session)

Specs

get_window_size(t) :: %{optional(String.t) => pos_integer, optional(String.t) => pos_integer}

Gets the size of the session’s window.

page_source(session)

Specs

page_source(t) :: String.t

Retrieves the source of the current page.

page_title(session)

Specs

page_title(t) :: String.t

Gets the title for the current page

send_keys(session, keys)

Specs

send_keys(t, [atom]) :: t

Sends a list of key strokes to active element. Keys should be provided as a list of atoms, which are automatically converted into the corresponding key codes.

For a list of available key codes see Wallaby.Helpers.KeyCodes.

Example

iex> Wallaby.Session.send_keys(session, [:enter])
iex> Wallaby.Session.send_keys(session, [:shift, :enter])
send_text(session, text)

Specs

send_text(t, String.t) :: t

Sends text characters to the active element

set_window_size(session, width, height)

Specs

set_window_size(t, pos_integer, pos_integer) :: t

Sets the size of the sessions window.

take_screenshot(screenshotable)

Specs

take_screenshot(Wallaby.Node.t | t) ::
  Wallaby.Node.t |
  t

Takes a screenshot of the current window. Screenshots are saved to a “screenshots” directory in the same directory the tests are run in.

visit(session, path)

Specs

visit(t, String.t) :: t

Changes the current page to the provided route. Relative paths are appended to the provided base_url. Absolute paths do not use the base_url.