This article was originally published on Jo4 Blog.

We deleted approximately 10,000 lines of old EC2 Terraform infrastructure and replaced it with 1,637 lines of Playwright E2E tests that prove our entire "publisher gets paid" flow works -- from signup to settlement -- in seconds instead of months.

The tests themselves? Straightforward. The setup? Five separate rabbit holes, each deeper than the last.

TL;DR

Auth0 SPA SDK writes tokens to localStorage asynchronously after handleRedirectCallback(). Playwright's waitForLoadState('networkidle') fires before those writes complete. You need page.waitForFunction() to poll for the exact localStorage key. Also, you need a test-only controller gated by @ConditionalOnProperty to bypass time-based business logic. Here are all five things that cost me more time than writing the test assertions.