hound v1.0.2 Hound.Helpers.Session

Session helpers

Summary

Functions

Switches to another session

When running multiple browser sessions, calling this function will switch to the default browser session

Ends a Hound session that is associated with a pid

Execute commands in a seperate browser session

Starts a Hound session

Functions

change_session_to(session_name, opts \\ [])

Switches to another session.

When you need more than one browser session, use this function switch to another session. If the session doesn’t exist it a new one will be created for you. All further commands will then run in the session you switched to.

# Pass any name to the session to refer to it later.
change_session_to("random-session")

The name can be an atom or a string. The default session created is called :default.

change_to_default_session()

When running multiple browser sessions, calling this function will switch to the default browser session.

change_to_default_session

# is the same as calling
change_session_to(:default)
end_session(pid \\ self())

Ends a Hound session that is associated with a pid.

If you have multiple sessions, all of those sessions are killed.

in_browser_session(session_name, func)

Execute commands in a seperate browser session.

in_browser_session "another_user", fn ->
  navigate_to "http://example.com"
  click({:id, "announcement"})
end
start_session(opts \\ [])

Starts a Hound session.

Use this in your test case’s setup block to start a Hound session for each test case. The session will be terminated when the caller process exits or when end_session/0 is explicitly called.

defmodule HoundTest do
  use ExUnit.Case
  use Hound.Helpers

  setup do
    Hound.start_session
    :ok
  end

  test "the truth", meta do
    navigate_to("http://example.com/guestbook.html")

    find_element(:name, "message")
    |> fill_field("Happy Birthday ~!")
    |> submit_element()

    assert page_title() == "Thank you"
  end

end

Options

The following options can be passed to start_session:

  • :browser - The browser to be used ("chrome" | "phantomjs" | "firefox")
  • :user_agent - The user agent string that will be used for the requests. The following atoms can also be passed

    • :firefox_desktop (aliased to :firefox)
    • :chrome_desktop (aliased to :chrome)
    • :phantomjs
    • :chrome_android_sp (aliased to :android)
    • :safari_iphone (aliased to :iphone)
  • :metadata - The metadata to be included in the requests. See Hound.Metadata for more information
  • :driver - The additional capabilities to be passed directly to the webdriver.