1

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)
4

2 回答 2

0

这当然不是您的测试套件的问题,因为在使用 Elixir 1.5 或更高版本和 Phoenix 1.3 时,此问题非常常见。可能在日志上方的某处,您可能会发现如下内容:

** (DBConnection.OwnershipError) cannot find ownership process for 
#PID....

尝试运行TEST环境的所有迁移,然后重新运行测试。你可以用一个命令来做到这一点:

MIX_ENV=test mix ecto.reset && mix test

ecto.reset将重置您的数据库(检查您的mix.exs文件),这是重新创建数据库、迁移它并再次运行种子的别名。

于 2017-11-20T06:19:35.743 回答
0

原来这是一个复制/粘贴问题

我的 repo 在一个单独的应用程序中,所以在 FeatureCase 中我替换WallabyTestWeb.RepoWallabyTest.Repo,现在测试很开心!

e:提示是我只在运行测试时在日志中收到 Postgres 错误,而不是在执行mix ecto.reset.

于 2017-11-23T08:00:15.023 回答