-
-
Save keathley/6ecd6bcdb46f096fc391ea7ea4da282c to your computer and use it in GitHub Desktop.
Example Wallaby tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session | |
|> click(“Some Async Button”) | |
|> find(“.async-result”) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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”) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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