Course contentsShow
← Computer Science
Lesson 2251 of 2,87250. Software TestingFree lesson

Writing Your First E2E Test

Basic structure of an E2E test: navigating pages, interacting with UI elements, submitting forms, and asserting expected outcomes.

Writing Your First E2E Test

You'll learn the fundamental structure of an end-to-end test: navigating, interacting, and asserting.

The Basic Building Blocks

An E2E test simulates a real user's journey through your application from start to finish. Think of it like writing a screenplay where you direct every action a user takes—clicking buttons, filling forms, and checking what appears on screen.

Every E2E test follows a predictable pattern:

1. Navigation

Start by directing your test to load a specific page, just like a user typing a URL into their browser.

2. Interaction

Simulate user actions: clicking links or buttons, typing into text fields, selecting dropdown options, or checking boxes. These commands find UI elements (usually by ID, class, or text) and perform actions on them.

3. Form Submission

For workflows involving data entry, your test fills out forms and submits them—exactly as a user would press "Submit" or "Login."

4. Assertion

Finally, verify the expected outcome. Did the success message appear? Did the page redirect correctly? Are the right items displayed? Assertions are your checkpoints that confirm the application behaved as intended.

Putting It Together

A typical first E2E test might verify a login flow: navigate to the login page, enter credentials into username and password fields, click the login button, then assert that the dashboard page loads with a welcome message. Each step builds on the previous one, creating a complete user story from beginning to end.

The test environment you set up earlier provides the browser automation, allowing your test code to control a real or headless browser programmatically.

Key Takeaway: An E2E test follows a simple flow—navigate to pages, interact with UI elements, submit forms, and assert expected outcomes to verify complete user workflows work correctly.