Skip to content

Instantly share code, notes, and snippets.

@ityonemo
Created March 16, 2026 20:55
Show Gist options
  • Select an option

  • Save ityonemo/ff3bb9a53d6d9d410465b520f4807048 to your computer and use it in GitHub Desktop.

Select an option

Save ityonemo/ff3bb9a53d6d9d410465b520f4807048 to your computer and use it in GitHub Desktop.
integration browser case
defmodule Integration.BrowserCase do
@moduledoc """
This module defines the setup for browser integration tests.
It sets up the Ecto sandbox and provides sandbox metadata to Playwright
so browser requests can share the test transaction.
Tests using this module must be tagged with `@moduletag :integration`.
"""
use ExUnit.CaseTemplate
using do
quote do
import Integration.BrowserCase
alias Integration.Playwright
end
end
setup tags do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Data.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
# Get sandbox metadata for Playwright
metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(Data.Repo, pid)
encoded_metadata = Phoenix.Ecto.SQL.Sandbox.encode_metadata(metadata)
# Store in process dictionary for Playwright.run!/2 to access
Process.put(:sandbox_metadata, encoded_metadata)
# Create test user
user = Mishras.Factory.insert(Data.User, %{name: "Test User", email: "test@example.com"})
{:ok, user: user, sandbox_metadata: encoded_metadata}
end
@doc """
Returns viewport dimensions for mobile devices (iPhone SE).
"""
def mobile_viewport, do: %{width: 375, height: 667}
@doc """
Returns viewport dimensions for tablets (iPad).
"""
def tablet_viewport, do: %{width: 768, height: 1024}
@doc """
Returns viewport dimensions for desktop screens.
"""
def desktop_viewport, do: %{width: 1280, height: 800}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment