Issue with testing - "Cannot find ownership process for #PID<0.564.0>

This is my first time using Wallaby and I am not sure how to resolve this issue - (DBConnection.OwnershipError) cannot find ownership process for #PID<0.564.0>.

This is my login_test.exs

defmodule E2E.LoginTest do
  use ExUnit.Case, async: false
  use Wallaby.Feature

  import Wallaby.Browser
  import Wallaby.Query, only: [text_field: 1, button: 1, css: 2]
  alias Wallaby.{Element, Query}

  setup do
    # Explicitly get a connection before each test
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(Calorie.Repo)
  end

  test "a user can register with the system" do
    {:ok, session} = Wallaby.start_session()
    session
    |> visit("http://localhost:4000/users/new")
    |> fill_in(text_field("Name"), with: "test2")
    |> fill_in(text_field("Username"), with: "test2")
    |> fill_in(text_field("Password"), with: "123Pasword123")
    |> find(Query.text("Create User"), fn el -> Element.click(el) end)


   Process.sleep(20_000)
   assert_text(session, "Listing Users")

  end
end

I will be grateful for explanation and help.

Hi.

When using use Wallaby.Feature, you don’t need to check out a db connection manually.

Thanks for the reply!

So I don’t need this setup do section? When I comment it out I still get this same issue.

You should write your test with the feature macro. it is what automatically does the db stuff for you. You can find the documentation here

defmodule E2E.LoginTest do
  use ExUnit.Case, async: false
  use Wallaby.Feature

  feature "a user can register with the system", %{session: session} do
    session
    |> visit("/users/new") #normally you'll want to do `Routes.user_path(Endpoint, :new)` here
    |> fill_in(Query.text_field("Name"), with: "test2")
    |> fill_in(Query.text_field("Username"), with: "test2")
    |> fill_in(Query.text_field("Password"), with: "123Pasword123")
    |> click(Query.button("Create User"))


   Process.sleep(20_000)
   assert_text(session, "Listing Users")
  end
end
2 Likes