elixirphoenix-frameworkwallaby

Wallaby Ecto.Registry.lookup error


I'm trying to get Wallaby working on a new Phoenix project. I've followed the setup instructions in the readme, but when I try to run a basic test I get an Ecto registry error:

1) test home page has welcome message (WallabyTestWeb.HomePageTest)
     test/wallaby_test_web/features/home_page_test.exs:6
     ** (ArgumentError) argument error
     stacktrace:
       (stdlib) :ets.lookup_element(Ecto.Registry, nil, 3)
       (ecto) lib/ecto/registry.ex:18: Ecto.Registry.lookup/1
       (ecto) lib/ecto/adapters/sql/sandbox.ex:529: Ecto.Adapters.SQL.Sandbox.proxy_pool/1
       (ecto) lib/ecto/adapters/sql/sandbox.ex:469: Ecto.Adapters.SQL.Sandbox.checkout/2
       (wallaby_test) test/support/feature_case.ex:18: WallabyTestWeb.FeatureCase.__ex_unit_setup_0/1
       (wallaby_test) test/support/feature_case.ex:1: WallabyTestWeb.FeatureCase.__ex_unit__/2
       test/wallaby_test_web/features/home_page_test.exs:1: WallabyTestWeb.HomePageTest.__ex_unit__/2

Here's the failing test:

defmodule WallabyTestWeb.HomePageTest do
  use WallabyTestWeb.FeatureCase, async: true

  import Wallaby.Query

  test "home page has welcome message", %{session: session} do
    require IEx
    IEx.pry()

    session
    |> visit("/")
    |> assert_has(css("h2", text: "Welcome to Phoenix!"))
  end
end

Here's the feature case:

defmodule WallabyTestWeb.FeatureCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Wallaby.DSL

      alias WallabyTestWeb.Repo
      import Ecto
      import Ecto.Changeset
      import Ecto.Query

      import WallabyTestWeb.Router.Helpers
    end
  end

  setup tags do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(WallabyTestWeb.Repo)

    unless tags[:async] do
      Ecto.Adapters.SQL.Sandbox.mode(WallabyTestWeb.Repo, {:shared, self()})
    end

    metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(WallabyTestWeb.Repo, self())
    {:ok, session} = Wallaby.start_session(metadata: metadata)
    {:ok, session: session}
  end
end

Here's the entire PR with my setup changes: https://github.com/marcdel/wallaby_test/pull/1/files

I'm using Elixir 1.6, PhantomJs 2.1.1.

$ elixir --version
Erlang/OTP 20 [erts-9.1.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.6.0-dev (882c2bd) (compiled with OTP 20)

$ brew info phantomjs
phantomjs: stable 2.1.1 (bottled)

Solution

  • Turns out it was a copy/paste issue 😞

    My repo is in a separate app so in FeatureCase I replaced WallabyTestWeb.Repo with WallabyTest.Repo, and now the tests are happy!

    e: the tip off was that I was only getting Postgres errors in the logs when running the test, not when doing mix ecto.reset.