In this episode, we dive right into creating our first end-to-end (E2E) test with Laravel Dusk, focusing on the user registration flow using the Breeze starter kit. We'll only stick with Breeze for this initial experience and will later expand to building our own functionality.
First, you'll see how to generate a Dusk test using php artisan dusk:make
and explore the auto-generated test class. We talk about focusing on the "happy path" (best-case scenario) and intentionally skip things like validation, since those are better off tested with feature tests to keep your E2E suite from getting brittle.
Next, we start filling out the registration form like a real user would: typing into input fields, mimicking button clicks, and running our test to see if it works. A cool tip in here is using Dusk's screenshot feature to visually confirm what your test is doing at any step.
Along the way, we run into some bumps—like not being able to find the Register button because of how the text appears on the page (turns out, case-sensitivity matters!). We fix the selector and talk about best practices for targeting elements in your tests (with improvements coming in later episodes).
Once we've got things filling correctly, we take a look at asserting that the user is authenticated and correctly redirected. This introduces one of the key concepts in E2E tests: waiting. Unlike unit or feature tests where everything happens instantly, browser-based E2E tests need to patiently wait for navigation, redirects, or elements to appear, and we show how to do just that.
The episode wraps with a reminder that E2E testing is about thinking like your users and replicating their actions as closely as possible, always checking your assumptions by manually running through the process yourself if things get confusing. As we go further in the course, we’ll keep refining and improving our test code!