Packages
wallaby
0.30.5
0.31.0
0.30.12
0.30.11
0.30.10
0.30.9
0.30.8
0.30.7
0.30.6
0.30.5
0.30.4
0.30.3
0.30.2
0.30.1
0.30.0
0.29.1
0.29.0
0.28.1
0.28.0
0.27.0
0.26.2
0.26.1
0.26.0
0.25.1
0.25.0
0.24.1
0.24.0
0.23.0
0.22.0
0.21.0
0.20.0
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.17.0
0.16.1
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.1
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.1
0.3.0
0.2.0
0.1.0
0.0.1
Concurrent feature tests for elixir
Current section
Files
Jump to
Current section
Files
lib/wallaby.ex
defmodule Wallaby do
@moduledoc """
A concurrent feature testing library.
## Configuration
Wallaby supports the following options:
* `:otp_app` - The name of your OTP application. This is used to check out your Ecto repos into the SQL Sandbox.
* `:screenshot_dir` - The directory to store screenshots.
* `:screenshot_on_failure` - if Wallaby should take screenshots on test failures (defaults to `false`).
* `:max_wait_time` - The amount of time that Wallaby should wait to find an element on the page. (defaults to `3_000`)
* `:js_errors` - if Wallaby should re-throw JavaScript errors in elixir (defaults to true).
* `:js_logger` - IO device where JavaScript console logs are written to. Defaults to :stdio. This option can also be set to a file or any other io device. You can disable JavaScript console logging by setting this to `nil`.
"""
@drivers %{
"chrome" => Wallaby.Chrome,
"selenium" => Wallaby.Selenium
}
use Application
alias Wallaby.Session
alias Wallaby.SessionStore
@doc false
def start(_type, _args) do
import Supervisor.Spec, warn: false
case driver().validate() do
:ok -> :ok
{:error, exception} -> raise exception
end
children = [
{driver(), [name: Wallaby.Driver.Supervisor]},
:hackney_pool.child_spec(:wallaby_pool,
timeout: 15_000,
max_connections: System.schedulers_online()
),
{Wallaby.SessionStore, [name: Wallaby.SessionStore]}
]
opts = [strategy: :one_for_one, name: Wallaby.Supervisor]
Supervisor.start_link(children, opts)
end
@type reason :: any
@type start_session_opts :: {atom, any}
@doc """
Starts a browser session.
## 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:
```
@message_field Query.text_field("Share Message")
@share_button Query.button("Share")
@message_list Query.css(".messages")
test "That multiple sessions work" do
{:ok, user1} = Wallaby.start_session
user1
|> visit("/page.html")
|> fill_in(@message_field, with: "Hello there!")
|> click(@share_button)
{:ok, user2} = Wallaby.start_session
user2
|> visit("/page.html")
|> fill_in(@message_field, with: "Hello yourself")
|> click(@share_button)
assert user1 |> find(@message_list) |> List.last |> text == "Hello yourself"
assert user2 |> find(@message_list) |> List.first |> text == "Hello there"
end
```
"""
@spec start_session([start_session_opts]) :: {:ok, Session.t()} | {:error, reason}
def start_session(opts \\ []) do
with {:ok, session} <- driver().start_session(opts),
:ok <- SessionStore.monitor(session),
do: {:ok, session}
end
@doc """
Ends a browser session.
"""
@spec end_session(Session.t()) :: :ok | {:error, reason}
def end_session(%Session{driver: driver} = session) do
with :ok <- SessionStore.demonitor(session) do
driver.end_session(session)
end
end
@doc false
def screenshot_on_failure? do
Application.get_env(:wallaby, :screenshot_on_failure)
end
@doc false
def js_errors? do
Application.get_env(:wallaby, :js_errors, true)
end
@doc false
def js_logger do
Application.get_env(:wallaby, :js_logger, :stdio)
end
def driver do
Map.get(
@drivers,
System.get_env("WALLABY_DRIVER"),
Application.get_env(:wallaby, :driver, Wallaby.Chrome)
)
end
end