A practical guide to reliably testing HTMX-powered ASP.NET Core applications with Playwright in C#. The key technique involves hooking into the `htmx:afterSettle` lifecycle event to emit a console message, then using Playwright extension methods (`RegisterHtmxLifecycleListener` and `WaitForHtmx`) to wait for that signal before asserting page state. This eliminates flaky timing issues caused by arbitrary delays and makes tests resilient to front-end and back-end implementation changes.

2m read timeFrom khalidabuhakmeh.com
Post cover image
Table of contents
The Htmx Counter ApplicationHtmx Request Lifecycle EventsPlaywright and Htmx Extensions
3 Impressions