hmu.ai
Back to Builder Agents
Builder Agent

Hyper-Focused Automated E2E Test Scenario Script for Freelance Developers

Stop doing this manually. Deploy an autonomous Builder agent to handle automated e2e test scenario script entirely in the background.

Zero-Shot Command Setup

Generate an automated E2E test script using Playwright for a user login and product purchase flow on an e-commerce site. The scenario involves: 1. Navigating to the login page. 2. Entering valid credentials. 3. Verifying successful login (e.g., seeing a dashboard). 4. Searching for a product (e.g., "laptop"). 5. Adding the first result to the cart. 6. Proceeding to checkout. 7. Verifying the order confirmation page.

Core Benefits & ROI

  • Catches critical bugs early in the release cycle
  • Ensures core user flows remain functional
  • Reduces manual testing effort and costs
  • Increases confidence in software releases
  • Provides consistent and repeatable test results
  • Improves product quality and user satisfaction

Ecosystem Integration

This "Builder" agent is a cornerstone for the **Testing** pillar, enabling freelance developers to rapidly create robust E2E test suites. By automating critical user flows, it directly contributes to higher software quality and faster feedback loops. It also profoundly impacts the **Deployment** pillar by increasing confidence in releases, as core functionalities are consistently validated. Finally, it reinforces the **Development** pillar by catching regressions early, preventing them from accumulating into larger, more costly issues.

Sample Output

```javascript // File: tests/e2e/productPurchase.spec.js const { test, expect } = require('@playwright/test'); test.describe('E-commerce User Login and Product Purchase Flow', () => { // Define user credentials and product for the test const USERNAME = 'testuser@example.com'; const PASSWORD = 'password123'; const PRODUCT_SEARCH_TERM = 'laptop'; test('should allow a user to log in and successfully purchase a product', async ({ page }) => { // 1. Navigate to the login page await test.step('Navigate to login page', async () => { await page.goto('https://www.your-ecommerce-site.com/login'); // Replace with actual login URL await expect(page).toHaveURL(/.*login/); await expect(page.locator('h1')).toHaveText('Login'); // Verify header }); // 2. Enter valid credentials await test.step('Enter valid credentials and log in', async () => { await page.fill('input[name="email"]', USERNAME); await page.fill('input[name="password"]', PASSWORD); await page.click('button[type="submit"]'); await page.waitForLoadState('networkidle'); }); // 3. Verify successful login (e.g., seeing a dashboard or user-specific element) await test.step('Verify successful login', async () => { await expect(page).toHaveURL(/.*dashboard|.*home/); // Replace with actual post-login URL regex await expect(page.locator('.user-greeting')).toContainText('Welcome, testuser'); // Example: check for a welcome message console.log('Successfully logged in.'); }); // 4. Searching for a product (e.g., "laptop") await test.step('Search for a product', async () => { await page.fill('input[name="search"]', PRODUCT_SEARCH_TERM); // Replace with actual search input selector await page.press('input[name="search"]', 'Enter'); // Simulate pressing Enter await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/.*search\?q=laptop/); // Verify search results URL await expect(page.locator('.product-listing')).toBeVisible(); // Verify product listings are visible console.log(`Searched for: ${PRODUCT_SEARCH_TERM}`); }); // 5. Adding the first result to the cart await test.step('Add the first product to the cart', async () => { await page.locator('.product-item').first().click(); // Click on the first product in the list await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/.*product\/.*/); // Verify product detail page await page.click('button:has-text("Add to Cart")'); // Click add to cart button await page.waitForSelector('.cart-notification:has-text("Item added to cart")', { state: 'visible' }); // Verify notification console.log('Product added to cart.'); }); // 6. Proceeding to checkout await test.step('Proceed to checkout', async () => { await page.click('a:has-text("View Cart")'); // Or a direct checkout button await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/.*cart/); // Verify cart page await page.click('button:has-text("Proceed to Checkout")'); // Click checkout button await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/.*checkout/); // Verify checkout page // Assuming default shipping/payment are pre-selected or can be skipped for this E2E test // If not, add steps here to fill shipping/payment details await page.click('button:has-text("Place Order")'); // Final order placement await page.waitForLoadState('networkidle'); }); // 7. Verifying the order confirmation page await test.step('Verify order confirmation', async () => { await expect(page).toHaveURL(/.*order-confirmation|.*thank-you/); // Verify order confirmation URL await expect(page.locator('h1')).toContainText('Order Confirmation'); await expect(page.locator('.order-summary')).toBeVisible(); console.log('Order confirmed successfully!'); }); }); }); ```

Frequently Asked Questions

How can I handle dynamic data or different test users in E2E tests?

For dynamic data, you can integrate test data generation libraries, use environment variables, or fetch data from a test API before running the test. For different test users, you can create multiple `test` blocks, each with unique credentials, or use a data-driven testing approach where a single test iterates over a list of user profiles.

What are the best practices for maintaining E2E tests generated by this agent?

Regularly review and update selectors if UI changes, use descriptive names for tests and steps, encapsulate common actions into reusable functions, and integrate tests into your CI/CD pipeline for automatic execution on every code change. Prioritize testing critical user paths and avoid over-testing minor UI elements that are prone to frequent changes.