Skip to content

Instantly share code, notes, and snippets.

@keathley
Last active April 15, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keathley/6ecd6bcdb46f096fc391ea7ea4da282c to your computer and use it in GitHub Desktop.
Save keathley/6ecd6bcdb46f096fc391ea7ea4da282c to your computer and use it in GitHub Desktop.
Example Wallaby tests.
session
|> click(“Some Async Button”)
|> find(“.async-result”)
defmodule YourApp.UsersChatTest do
use YourApp.AcceptanceCase, async: true
def checkout_session do
{:ok, session} = Wallaby.start_session
visit(session, Phoenix.Ecto.SQL.Sandbox.path_for(Allocations.Repo, self()))
session
end
test “users can chat”, %{session: browser_one} do
browser_one
|> find(“.chat-messages”, count: 0)
browser_two
|> checkout_session
|> find(“.chat-messages”, count: 0)
browser_two
|> find(“.new-message-form”)
|> fill_in(“Chat Message”, with: “Hello There!”)
|> click(“Send”)
new_message =
browser_one
|> find(“.chat-messages”, count: 1)
assert has_text?(new_message, “Hello There!”)
end
end
fill_in(session, “#last_name_field”, with: “Grace”)
fill_in(session, “Last Name”, with: “Hopper”)
choose(session, “Radio Button 1”)
check(session, “Checkbox”)
uncheck(session, “Checkbox”)
select(session, “My Awesome Select”, option: “Option 1”)
click(session, “Some Button”)
click_link(session, “Page 1”)
defmodule YourApp.UserListTest do
use YourApp.AcceptanceCase, async: true
test “users have names”, %{session: session} do
first_employee =
session
|> visit(“/users”)
|> find(“.dashboard”)
|> all(“.user”)
|> List.first
|> find(“.user-name”)
assert has_text?(first_employee, “Chris”)
end
end
defmodule YourApp.UserRegistrationTest do
use YourApp.AcceptanceCase, async: true
test “users can register”, %{session: session} do
session
|> visit(“/users/new”)
|> find(“.registration_form”)
|> fill_in(“Full Name”, with: “Grace Hopper”)
|> fill_in(“Email”, with: “grace@hoppper.com”)
|> fill_in(“Password”, with: “password”)
|> click(“Register”)
assert has_text?(session, “Welcome Grace Hopper”)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment