When to use LiveViewTest vs Playwright

LiveView uses Playwright for e2e testing, whilst also shipping with LiveViewTest

They both have there pros, but the biggest ones (to me) are:

  • Playwight - codegen (the ability to interactively create your tests in the browser very quickly)
  • LiveViewTest - (is probably) a lot quicker to run a significant amount of tests & native integration for component testing

I was wondering how other people decide when to use which one, or if they only use either Playwight or LiveViewTest (or another!).

From how I see it, LiveViewTest has the advantage of it being able to do both component and e2e tests, however it’s much quicker (for a developer) to make e2e tests in Playwright.

For e2e tests, there is also Wallaby.

It’s all about whether you want a battery-included solution or you are OK with doing/maintaining a part of the setup yourself. LiveViewTest as you mentioned is a unified tool for all your phoenix test needs, it requires zero setup if you have a phoenix project, but at the same time it’s obviously not as flexible as using the dependency directly.

1 Like

To me the biggest consideration is that if you need to execute your js hooks then you’ll need a full e2e runner like Playwright or Wallaby since LiveViewTest runs only the Elixir code.

3 Likes

There’s currently work happening on phoenix_test to make playwright another driver for it, so switching to it would become a config switch.

8 Likes

Here’s the mentioned Playwright driver for PhoenixTest:

defmodule Features.RegisterTest do
  use PhoenixTest.Playwright.Case

  @tag trace: :open                      # replay in interactive viewer
  test "register", %{conn: conn} do
    conn
    |> visit(~p"/")
    |> click_link("Register")
    |> fill_in("Email", with: "f@ftes.de")
    |> click_button("Create an account")
    |> assert_has(".text-rose-600", text: "required")
  end
end