Slide 1

Slide 1 text

Concurrent Feature Tests with Wallaby Chris Keathley / @ChrisKeathley / [email protected]

Slide 2

Slide 2 text

Feature tests: Driving tests from the UI

Slide 3

Slide 3 text

Name email Password Sign Up

Slide 4

Slide 4 text

Name email Password Sign Up Fill in

Slide 5

Slide 5 text

Name email Password Sign Up Fill in Click

Slide 6

Slide 6 text

Thanks for signing up! Did this show up?

Slide 7

Slide 7 text

Feature Tests

Slide 8

Slide 8 text

Feature Tests Represent real users

Slide 9

Slide 9 text

Feature Tests Represent real users Provide Confidence in the System

Slide 10

Slide 10 text

Feature Tests Represent real users Provide Confidence in the System Dark Side

Slide 11

Slide 11 text

Feature Tests Represent real users Provide Confidence in the System

Slide 12

Slide 12 text

Feature Tests Represent real users Provide Confidence in the System (Sometimes)

Slide 13

Slide 13 text

Feature Tests Represent real users Provide Confidence in the System (Sometimes) (When they aren’t randomly failing)

Slide 14

Slide 14 text

Happens

Slide 15

Slide 15 text

Feature Tests ARE Slow

Slide 16

Slide 16 text

Wallaby

Slide 17

Slide 17 text

Wallaby Manages multiple browsers Concurrent Assumes async Interfaces

Slide 18

Slide 18 text

Wallaby TL;DR

Slide 19

Slide 19 text

Name email Password Sign Up

Slide 20

Slide 20 text

defmodule YourApp.UserRegistrationTest do use YourApp.AcceptanceCase, async: true test "users can register", %{session: session} do end end

Slide 21

Slide 21 text

defmodule YourApp.UserRegistrationTest do use YourApp.AcceptanceCase, async: true test "users can register", %{session: session} do session end end

Slide 22

Slide 22 text

defmodule YourApp.UserRegistrationTest do use YourApp.AcceptanceCase, async: true test "users can register", %{session: session} do session |> visit("/users/new") end end

Slide 23

Slide 23 text

defmodule YourApp.UserRegistrationTest do use YourApp.AcceptanceCase, async: true test "users can register", %{session: session} do session |> visit("/users/new") |> find(".registration_form") end end

Slide 24

Slide 24 text

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: "[email protected]") |> fill_in("Password", with: "password") end end

Slide 25

Slide 25 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") end end

Slide 26

Slide 26 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text end end

Slide 27

Slide 27 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end

Slide 28

Slide 28 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end

Slide 29

Slide 29 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end

Slide 30

Slide 30 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end

Slide 31

Slide 31 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 32

Slide 32 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 33

Slide 33 text

Wallaby Phoenix EcTo Test Sessions

Slide 34

Slide 34 text

Wallaby Phoenix EcTo Test Sessions Browser

Slide 35

Slide 35 text

Wallaby Phoenix EcTo Test Sessions Browser Browser

Slide 36

Slide 36 text

Wallaby Phoenix EcTo Test Sessions Browser

Slide 37

Slide 37 text

setup tags do {:ok, session} = Wallaby.start_session([]) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 38

Slide 38 text

Browser Browser Phoenix Ecto

Slide 39

Slide 39 text

Browser Browser Phoenix Ecto

Slide 40

Slide 40 text

Browser Browser Phoenix Ecto

Slide 41

Slide 41 text

Browser Phoenix Ecto

Slide 42

Slide 42 text

Browser Phoenix Ecto Ownership Metadata

Slide 43

Slide 43 text

Browser Phoenix Ecto Ownership Metadata Transaction Ownership

Slide 44

Slide 44 text

setup tags do {:ok, session} = Wallaby.start_session([]) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 45

Slide 45 text

setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(YourApp.Repo) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for( YourApp.Repo, self()) {:ok, session} = Wallaby.start_session(metadata: metadata) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 46

Slide 46 text

setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(YourApp.Repo) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for( YourApp.Repo, self()) {:ok, session} = Wallaby.start_session(metadata: metadata) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 47

Slide 47 text

setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(YourApp.Repo) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for( YourApp.Repo, self()) {:ok, session} = Wallaby.start_session(metadata: metadata) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 48

Slide 48 text

setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(YourApp.Repo) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for( YourApp.Repo, self()) {:ok, session} = Wallaby.start_session(metadata: metadata) on_exit, fn -> Wallaby.end_session(session) end {:ok, session: session} end

Slide 49

Slide 49 text

defmodule YourApp.Endpoint do use Phoenix.Endpoint, otp_app: :your_app if Application.get_env(:your_app, :sql_sandbox) do plug Phoenix.Ecto.SQL.Sandbox end plug YourApp.Router end

Slide 50

Slide 50 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 51

Slide 51 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 52

Slide 52 text

Thanks for signing up!

Slide 53

Slide 53 text

Thanks for signing up!
Thanks for signing up!

Slide 54

Slide 54 text

Thanks for signing up!
Thanks for signing up!
session |> find(“.alert")

Slide 55

Slide 55 text

Thanks for signing up!
Thanks for signing up!
session |> find(“.alert")

Slide 56

Slide 56 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML

Slide 57

Slide 57 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session

Slide 58

Slide 58 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session |> find(".user")

Slide 59

Slide 59 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session |> find(".user") Ambiguous

Slide 60

Slide 60 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session |> find(".user", count: 2)

Slide 61

Slide 61 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session |> find(".user", count: 2) |> Enum.map(& find(&1, ".name") )

Slide 62

Slide 62 text

Grace Hopper [email protected]
Alan Turing [email protected]
HTML Test - User Names session |> find(".user", count: 2) |> Enum.map(& find(&1, ".name") ) |> Enum.map(& text(&1) ) # => ["Grace Hopper", "Alan Turing"]

Slide 63

Slide 63 text

session HTML Test - Grace’s Email
Grace Hopper [email protected]
Alan Turing [email protected]

Slide 64

Slide 64 text

session |> find(".user", text: "Grace Hopper") HTML Test - Grace’s Email
Grace Hopper [email protected]
Alan Turing [email protected]

Slide 65

Slide 65 text

session |> find(".user", text: "Grace Hopper") |> find(".email") HTML Test - Grace’s Email
Grace Hopper [email protected]
Alan Turing [email protected]

Slide 66

Slide 66 text

session |> find(".user", text: "Grace Hopper") |> find(".email") |> text # => "[email protected]" HTML Test - Grace’s Email
Grace Hopper [email protected]
Alan Turing [email protected]

Slide 67

Slide 67 text

find(".user") ? Browser

Slide 68

Slide 68 text

find(".user") JS Browser

Slide 69

Slide 69 text

find(".user") JS Browser

Slide 70

Slide 70 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 71

Slide 71 text

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: "[email protected]") |> fill_in("Password", with: "password") |> click("Register") msg_text = session |> find(".flash-message") |> text assert msg_text == "Welcome Grace Hopper" end end Sessions Queries actions

Slide 72

Slide 72 text

Name Sign Up

Slide 73

Slide 73 text

Name Register HTML

Slide 74

Slide 74 text

HTML Name Register

Slide 75

Slide 75 text

Name Register HTML Test session

Slide 76

Slide 76 text

Name Register HTML Test session |> fill_in("Name", with: "Grace Hopper")

Slide 77

Slide 77 text

Name Register HTML Test session |> fill_in("Name", with: "Grace Hopper") |> click_on("Register")

Slide 78

Slide 78 text

HTML Test session |> fill_in(“user_name", with: "Grace Hopper") |> click_on("Register") Name Register

Slide 79

Slide 79 text

HTML Test session |> fill_in(“user_name", with: "Grace Hopper") |> click_on("Register") Name Save login Register

Slide 80

Slide 80 text

HTML Test session |> fill_in(“user_name", with: "Grace Hopper”) |> check("Save login") |> click_on("Register") Name Save login Register

Slide 81

Slide 81 text

fill_in(session, "First Name", with: "Chris") choose(session, "Radio Button 1") check(session, "Checkbox") uncheck(session, "Checkbox") select(session, "My Awesome Select", option: "Option 1") click_on(session, "Some Button") attach_file(session, "File", path: "path/to/file") Other Actions

Slide 82

Slide 82 text

Wallaby Sessions Queries Interactions

Slide 83

Slide 83 text

Still More work to do!

Slide 84

Slide 84 text

https://github.com/keathley/wallaby https://speakerdeck.com/keathley Getting Started

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

Lets Build awesome stuff Together!

Slide 88

Slide 88 text

THANKS Chris Keathley / @ChrisKeathley / [email protected]