coen.bakker

coen.bakker

TLDR: Started using Wallaby. Running into some test bugs related to Ecto.Adapters.SQL.Sandbox. Wondering if making an IntegrationCase module is ill advised, or maybe even recommended? Asking because I feel like I can’t foresee all the ramifications well myself. It seems more difficult to know what SQL sandbox related things are happening when using use Wallaby.Feature.


I recently started using Wallaby for part of my tests. I am still digging through the documentation and setting up the first tests.

In the code examples of the documentation the Feature module is used in the tests (i.e., use Wallaby.Feature is declared at the top of a test). The documentation of the Feature module, however, also mentions the following.

If you don’t wish to use Wallaby.Feature in your test module, you can add the following code to configure Ecto and create a session.

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

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

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

  {:ok, session: session}
end

As far as I can tell there is no such thing as a IntegrationCase (or whatever name) module in Wallaby, in contrast to Elixir/Phoenix having DataCase, ConnCase and ChannelCase.

I am debugging some test bugs related to how Ecto.Adapters.SQL.Sandbox is setup. I was thinking that having a IntegrationCase would maybe be helpful in that process, because it seems more difficult to know what SQL sandbox related things are happening when doing use Wallaby.Feature.

Is it ill advised for me to make use of an IntegrationCase, rather than declaring use Feature in my test files? I did come across a mention of “IntegrationCase” in this 2017 article by Jake Worth. That’s some time ago, however, so I wanted to check what the status quo is.

Showing Posts 1 to 4

krasenyp

krasenyp

It would be helpful to share what are the bugs you’re encountering. Without this context, I don’t really understand the question and can’t help. Maybe you can check German Velasco’s book about testing Phoenix - https://www.tddphoenix.com/, it uses Wallaby.

coen.bakker

coen.bakker OP

Thank you for the reference to the book. I think it will come in very handy. I already spotted that it goes into setting up a FeatureCase.

The errors I am running into are ownership errors: ** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.xxx.0>. Specifically, I am running into an error when registering a user through the UI.

defmodule AppWeb.FirstFeatureTest do
  use ExUnit.Case, async: true
  use Wallaby.Feature
  alias Wallaby.Query

  @username_field Query.text_field("Username")
  @email_field Query.text_field("Email")
  @password_field Query.text_field("Password")
  @log_in_button Query.button("Sign in")
  @register_button Query.button("Create an account")

  feature "temp", %{session: session} do
    session =
      session
      |> visit("/users/register")
      |> fill_in(@username_field, with: "username")
      |> fill_in(@email_field, with: "username@example.com")
      |> fill_in(@password_field, with: "password1234")
      |> click(@register_button)

    :timer.sleep(200)
    take_screenshot(session)
  end
end

I am working my way through the part of the Wallaby and Ecto.Adapters.SQL.Sandbox documentation about the different possible modes of a sandbox pool. I am still in the process of wrapping my head around the ownership mechanism.

coen.bakker

coen.bakker OP

Having read more of the TDD Phoenix book and learnt about approaches to setting up a FeatureCase, I want to make sure not to confuse beginners with my original post.

To be clear, I made it seem in my post as if you need to choose between use.FeatureCase OR use Wallaby.Feature somehow. I am now using the FeatureCase described in the TDD Phoenix book. I my case I don’t use Wallaby.Feature. However, I have also seen approaches that use Wallaby.Feature inside a FeatureCase. For example, see this blog by Britton Broderick.

I choose the former approach, because I like to include this code snippet in my FeatureCase, instead of hiding it inside use Wallaby.Feature.

mhanberg

mhanberg

Expert LSP Core Team

If you want proper screenshots on failure, you’ll still want to use the feature macro by importing Wallaby.Feature

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews