Boosting Confidence with Comprehensive Playwright E2E Tests for Core Business Flows
In our Motos Max Cordialidad project, which manages motorcycle sales and services, maintaining high reliability for core business operations is paramount. While we had some initial test coverage, a significant gap existed in our end-to-end (E2E) testing for crucial business workflows.
The Situation
Before this work, our E2E testing primarily focused on foundational areas like authentication, customer management, and Progressive Web App (PWA) specific features. However, critical operational flows—such as creating reception orders, managing sales transactions, and updating inventory—lacked comprehensive automated validation. This meant that any changes to these vital parts of the application often necessitated extensive manual testing, introducing potential delays, human error, and increasing the risk of regressions making it to production.
The Solution
To address this, we embarked on a mission to significantly expand our E2E test suite using Playwright. The objective was to simulate real-world user interactions across the most vital business paths of the application. These tests were designed to run directly against our local API, ensuring that our automated checks reflected the true behavior of the system, including a real login process without mocks. This initiative involved creating dedicated test specifications for three core areas: reception-order, sales, and inventory.
Technical Deep Dive: Covering Critical Flows
Each new test specification was crafted to validate an entire business process from a user's perspective, providing a robust safety net for our development efforts.
Reception Order Flow (reception-order.spec.ts)
This suite covers the complete process of creating a new service order. Tests simulate a user:
- Creating a new customer record.
- Registering a new motorcycle, ensuring all mandatory fields (like engine number) are correctly handled.
- Assigning a mechanic to the order.
- Verifying that the order is successfully created and the application navigates to the correct work order details page.
import { test, expect } from '@playwright/test';
test('should create a new reception order', async ({ page }) => {
await page.goto('/login');
await page.fill('input[name="email"]', '[email protected]');
await page.fill('input[name="password"]', 'password123');
await page.click('button[type="submit"]');
await page.waitForURL('/dashboard');
await page.click('a[href="/reception/new"]');
await page.fill('input[name="customerName"]', 'New Client');
await page.fill('input[name="motorcycleMake"]', 'Honda');
await page.fill('input[name="engineNumber"]', 'ENG12345');
await page.selectOption('select[name="mechanic"]', { label: 'John Doe' });
await page.click('button:has-text("Create Order")');
await expect(page).toHaveURL(/\/work-orders\/\d+/);
await expect(page.locator('h1')).toContainText('Work Order Details');
});
Sales Flow (sales.spec.ts)
Our sales tests validate the entire sales transaction lifecycle, ensuring accuracy and proper state transitions. These tests include:
- Registering an available motorcycle for sale.
- Creating a new sales draft for a cash transaction.
- Confirming the sales draft, transitioning it to a completed sale.
import { test, expect } from '@playwright/test';
test('should complete a cash sales transaction', async ({ page }) => {
// Assume login is already handled or part of a setup hook
await page.goto('/sales/new');
await page.selectOption('select[name="motorcycleId"]', { index: 1 }); // Select first available motorcycle
await page.fill('input[name="price"]', '5000');
await page.click('button:has-text("Create Draft")');
await page.waitForURL(/\/sales\/draft\/\d+/);
await page.click('button:has-text("Confirm Sale")');
await expect(page.locator('.alert-success')).toContainText('Sale confirmed successfully');
});
Inventory Flow (inventory.spec.ts)
The inventory tests focus on verifying stock management accuracy, which is crucial for operational efficiency. These tests involve:
- Registering a new spare part into the system.
- Applying a stock entry (e.g., receiving new units).
- Verifying that the available stock quantity for that part correctly increases after the entry.
import { test, expect } from '@playwright/test';
test('should update inventory stock', async ({ page }) => {
// Assume login
await page.goto('/inventory/new-part');
await page.fill('input[name="partName"]', 'Brake Pad Set');
await page.click('button:has-text("Add Part")');
await page.waitForURL('/inventory');
// Navigate to stock entry for the new part
await page.click('button:has-text("Add Stock for Brake Pad Set")');
const initialStock = await page.locator('span[data-testid="current-stock"]').textContent();
await page.fill('input[name="quantity"]', '10');
await page.click('button:has-text("Apply Entry")');
await expect(page.locator('span[data-testid="current-stock"]')).toContainText(String(Number(initialStock) + 10));
});
Overcoming Challenges
A notable challenge during the development and execution of these tests was encountering the application's real API login throttle. Our authentication controller implements a security measure that limits login attempts (e.g., 5 attempts per 5 minutes per IP). While this is essential for security, running the entire E2E suite in a short loop could inadvertently hit this limit. This highlighted the importance of robust test setup, potential use of dedicated test environments or credentials with higher limits, and careful management of test execution order or retry mechanisms to avoid false failures due to temporary throttling.
The Takeaway
Expanding our Playwright E2E coverage for the Motos Max Cordialidad project's core business flows has significantly boosted our confidence in the application's stability and reliability. By simulating real user journeys against a live API, we've established a comprehensive safety net that catches regressions early, reduces manual testing effort, and ultimately leads to more reliable deployments and a smoother development experience. When implementing E2E tests, prioritize the most critical user flows, ensure they interact with the application as genuinely as possible (e.g., real API calls), and be mindful of system-level constraints like API rate limits that might affect test execution.
Generated with Gitvlg.com