8000 test(browser): move browser scenarios to Fluffy by ftes · Pull Request #705 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

test(browser): move browser scenarios to Fluffy - #705

Open
ftes wants to merge 14 commits into
huddlz-hq:mainfrom
ftes:fluffy-rc
Open

ftes wants to merge 14 commits into
huddlz-hq:mainfrom
ftes:fluffy-rc

Conversation

@ftes
@ftes ftes commented Nov 23, 2026 •
Copy link
Copy Markdown

Move browser tests from phoenix_test_playwright to fluffy (RC), based on the new major version of playwright_ex (also RC).

I'm the author of phoenix_test_playwright, playwright_ex and fluffy. I'm looking for some earlier adopters to validate everything in the new versions is working - and I thought the best way is to create PRs :).

I'd love to hear your feedback!

conn =
context.conn
|> press("#theme-menu-trigger", "Enter")
|> unwrap(&Playwright.Page.press!(&1, "#theme-menu-trigger", "Enter"))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the Playwright.Page.click!/press! calls through unwrap are non-strict, so they act on the first match. The phoenix_test_playwright calls they replace were strict and raised when a selector matched several elements. All tests pass as is; pass strict: true (or go through Page.locator/2) if you want that check back.

Comment thread test/browser/support/hooks.exs Outdated
context
# Cucumber creates the ExUnit modules, so no `use Playwright.Test` can
# register the scenario: run its per-test setup here.
Playwright.Test.__setup__(context)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Playwright.Test.__setup__/1 is internal to playwright_ex. It's needed because cucumber generates its scenario modules with a hardcoded use ExUnit.Case, so nothing can use Playwright.Test. The proper fix belongs upstream in cucumber: letting compile_features! take a case template (e.g. case_template: HuddlzWeb.BrowserCase) would let a template use Playwright.Test, which also gives each scenario real results for its screenshots and traces. Until then, this call is the stop-gap.

@ftes
ftes force-pushed the fluffy-rc branch 2 times, most recently from ed91390 to c0764ea Compare November 23, 2026 20:59
@mwoods79
Copy link
Copy Markdown
Contributor

Thanks for doing the port, Fredrik. We’re waiting for stable releases before adopting it. We ran the proposed migration locally and all 60 browser scenarios passed on both the PR and its base. Three things came out of the comparison.

  • Sandbox teardown. On the PR, each of four full runs logged Postgrex disconnects while HuddlzWeb.HuddlLive.Show was still using the connection. mix test.browser --only photo_browser --seed 1705 reproduces it even though all three scenarios pass. Moving Huddlz.DataCase.setup_sandbox(context) before Playwright.Test.__setup__(context) in the Cucumber hook cleared the disconnects in two focused runs and a full 60-scenario run. Restoring the original order brought the error back. ExUnit runs teardown callbacks in reverse registration order, so I’d make that swap.
  • Failure diagnostics. All 60 passing scenarios produced a screenshot named test-failed-1.png. I ran the appearance-menu scenario on its own, then deliberately made its assertion fail. ExUnit reported the right outcome both times, but both produced the same screenshot name and the failing trace omitted the assertion message. That gives us a concrete acceptance check for the Cucumber case-template support you mentioned.
  • Performance. On an Apple M5 Max, with the same Chromium build, one worker, screenshots and tracing enabled, median wall time for mix test.browser was 49.55 s on the base and 58.70 s on the PR. After one warm-up per version, the three paired runs were 55.04/55.73 s, 47.52/59.22 s, and 49.55/58.70 s (base/PR, seeds 1705, 2705, 3705). In one additional same-seed comparison with only tracing disabled, ExUnit reported 47.4 s on the base and 46.1 s on the PR. I’d profile trace recording first. That single run is too small to attribute the whole difference to tracing.

For a stable migration we’d also keep the old strict click and keypress behavior, as you flagged, so an accidentally duplicated control still fails the scenario.

@ftes
ftes commented Nov 25, 2026 •
Copy link
Copy Markdown
Author

Thanks for the careful comparison Micah!
I pushed a new version of this PR on Fluffy native API
(I know you're waiting for stable releases anyway, just for reference).

  • Sandbox: the sandbox now starts in a case template's own setup, so it stops after Playwright.Test has closed the browser contexts. That's the ordering fix you found, now structural.
  • Strictness: the steps use Fluffy's own API instead of raw Playwright calls through unwrap, so clicks and key presses fail again when a locator matches more than one element.
  • Diagnostics: cucumber now generates the scenario modules from that case template (feat: case_template option for generated feature modules cucumber#84) and wraps each Gherkin step (feat: step_wrapper option to wrap each step cucumber#85). Passing scenarios keep no artifacts; a failure keeps a screenshot, a trace with each Gherkin step and the assertion message, and an error-context.md with the scenario's file.feature:LINE. Until those PRs are released, the dep points at ftes/cucumber's playwright branch.
  • Performance: in my alternating same-machine runs, Fluffy was 10% slower even with tracing off. That's its 5 s expect timeout (Playwright Test's default) against phoenix_test_playwright's 2 s. Under 2.5 s Playwright re-checks every 100 ms, above it every 500 ms, which delays your debounced updates. With config :playwright, :test, expect: [timeout: 2_000] both ran equally fast. On top of that, Fluffy's fuller trace cost about 50 ms per scenario more, and traces are now kept for failed scenarios only.

ftes added 14 commits November 26, 2026 17:06
Steps act through Fluffy's strict locators, Keyboard and Mouse instead of
the PhoenixTest facade and Playwright.Page calls with selectors, so a
duplicated control fails the scenario again.
Cucumber now uses HuddlzWeb.BrowserCase in place of ExUnit.Case, so each
scenario is a Playwright.Test test and the hook no longer runs its per-test
setup. The template owns the sandbox, which stops after the contexts close.
Cucumber's step wrapper runs every step inside Playwright.Test.step, so a
trace groups each step's actions under its Given/When/Then line. It is set in
the browser suite's helper, as the fast suite's steps are no Playwright tests.
Playwright.Test now learns each scenario's result, so a passing run leaves no
per-scenario artifacts and CI's failure upload holds just the failures.
Fluffy has no step/2, so excluding it did nothing.
Cucumber now takes it as an option, so it wraps only the browser features
without setting the app env. Bumps the fork to d75ec023.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0