Harness e2e

From Intense-Visions/harness-engineering · View interactive version

Harness e2e is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > End-to-end browser testing with Playwright, Cypress, or Selenium. Covers page object scaffolding, critical-path test implementation, and systematic flakiness remediation.

How to use this skill

Skill file

Harness E2E

End-to-end browser testing with Playwright, Cypress, or Selenium. Covers page object scaffolding, critical-path test implementation, and systematic flakiness remediation.

When to Use

Process

Phase 1: DETECT -- Identify Framework and Application Structure

  1. Scan for E2E configuration. Search for playwright.config.ts, playwright.config.js, cypress.config.ts, cypress.config.js, wdio.conf.js, or selenium directories. If multiple frameworks are present, prefer the one with the most existing tests.
  1. Catalog existing E2E tests. Glob for *.spec.ts, *.e2e.ts, *.cy.ts, *.test.ts within E2E directories. Count tests per file and identify patterns: naming conventions, folder structure, shared utilities.
  1. Map application entry points. Identify the base URL, authentication flow, and route structure. Check for:
  1. Identify the test execution environment. Determine whether tests run against a dev server, a preview deployment, or a Docker Compose stack. Check package.json scripts for e2e, test:e2e, or playwright test commands.
  1. Report findings. Summarize: framework detected, number of existing tests, coverage gaps relative to application routes, and any configuration issues (missing base URL, no auth setup).

Phase 2: SCAFFOLD -- Generate Page Objects and Test Infrastructure

  1. Create the page object directory. Follow the project's existing conventions. If no convention exists, use e2e/pages/ for Playwright or cypress/pages/ for Cypress.
  1. Generate page objects for target flows. Each page object encapsulates:
  1. Create shared fixtures and helpers. Generate:
  1. Configure test parallelization. Set up:
  1. Verify scaffold compiles. Run the test command with --list or --dry-run to confirm all imports resolve and page objects instantiate without errors.

Phase 3: IMPLEMENT -- Write E2E Tests for Critical Paths

  1. Prioritize user flows by business impact. Order test implementation:
  1. Write each test following the Arrange-Act-Assert pattern.
  1. Use explicit waits, never arbitrary timeouts. Where the framework provides an auto-waiting mechanism (Playwright expect with auto-retry, Cypress implicit waits), rely on it. Where explicit waits are needed, wait for specific network responses, DOM mutations, or URL changes -- never page.waitForTimeout().
  1. Isolate tests from each other. Each test must:
  1. Tag tests by scope. Apply tags or annotations:
  1. Run the full E2E suite. Verify all tests pass locally before proceeding to validation.

Phase 4: VALIDATE -- Execute, Detect Flakiness, and Remediate

  1. Run the suite 3 times consecutively. Track pass/fail per test across runs. Any test that fails in at least one run but passes in another is flagged as flaky.
  1. Classify flaky tests by root cause. Common categories:
  1. Apply remediation for each flaky test. Do not simply add retries -- fix the root cause. Retries mask problems. After remediation, rerun the previously-flaky test 5 times to confirm stability.
  1. Run harness validate. Confirm the project passes all harness checks with the new E2E tests in place.
  1. Generate a coverage summary. Report:

Graph Refresh

If a knowledge graph exists at .harness/graph/, refresh it after code changes to keep graph queries accurate:

harness scan [path]

Harness Integration

Success Criteria

Examples

Example: Playwright E2E for a SaaS Dashboard

DETECT output:

Framework: Playwright 1.42 (playwright.config.ts found)
Existing tests: 12 specs in e2e/tests/
Base URL: http://localhost:3000
Auth: Cookie-based, no stored auth state found
Coverage gaps: settings page, billing flow, team invitation

SCAFFOLD -- Page object for dashboard:

// e2e/pages/dashboard.page.ts
import { type Page, type Locator, expect } from '@playwright/test';

export class DashboardPage {
  readonly page: Page;
  readonly heading: Locator;
  readonly projectList: Locator;
  readonly createButton: Locator;

  constructor(page: Page) {
    this.page = page;
    this.heading = page.getByRole('heading', { name: 'Dashboard' });
    this.projectList = page.getByTestId('project-list');
    this.createButton = page.getByRole('button', { name: 'New Project' });
  }

  async goto() {
    await this.page.goto('/dashboard');
    await expect(this.heading).toBeVisible();
  }

  async createProject(name: string) {
    await this.createButton.click();
    await this.page.getByLabel('Project name').fill(name);
    await this.page.getByRole('button', { name: 'Create' }).click();
    await expect(this.page.getByText(name)).toBeVisible();
  }

  async expectProjectCount(count: number) {
    await expect(this.projectList.getByRole('listitem')).toHaveCount(count);
  }
}

IMPLEMENT -- Critical path test:

// e2e/tests/project-creation.spec.ts
import { test, expect } from '@playwright/test';
import { DashboardPage } from '../pages/dashboard.page';
import { LoginPage } from '../pages/login.page';

test.describe('Project creation', () => {
  test('user can create a project from the dashboard', async ({ page }) => {
    // Arrange: authenticate via stored state
    const loginPage = new LoginPage(page);
    await loginPage.loginAs('test-user@example.com');

    // Act: create a new project
    const dashboard = new DashboardPage(page);
    await dashboard.goto();
    await dashboard.createProject('My Test Project');

    // Assert: project appears in the list
    await expect(page.getByText('My Test Project')).toBeVisible();
    await expect(page).toHaveURL(/\/projects\/[\w-]+/);
  });
});

Example: Cypress E2E for an E-Commerce Checkout

IMPLEMENT -- Checkout flow with network interception:

// cypress/e2e/checkout.cy.ts
describe('Checkout flow', () => {
  beforeEach(() => {
    cy.intercept('POST', '/api/orders', { fixture: 'order-success.json' }).as('createOrder');
    cy.loginByApi('customer@shop.com', 'testpass123');
  });

  it('completes checkout with valid payment', () => {
    cy.visit('/cart');
    cy.findByTestId('cart-item').should('have.length.at.least', 1);

    cy.findByRole('button', { name: 'Proceed to Checkout' }).click();
    cy.url().should('include', '/checkout');

    cy.findByLabelText('Card number').type('4242424242424242');
    cy.findByLabelText('Expiry').type('12/28');
    cy.findByLabelText('CVC').type('123');

    cy.findByRole('button', { name: 'Place Order' }).click();
    cy.wait('@createOrder');

    cy.findByRole('heading', { name: 'Order Confirmed' }).should('be.visible');
  });
});

Rationalizations to Reject

| Rationalization | Why It Is Wrong |

| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

| "Using CSS class selectors is faster than adding data-testid attributes" | No CSS class selectors in page objects. .btn-primary breaks when the design system updates class names. Use data-testid, ARIA roles, and accessible labels. |

| "Adding a short waitForTimeout is easier than figuring out the right wait condition" | No arbitrary waits is a hard gate. waitForTimeout is a flakiness timebomb. Wait for specific conditions: network responses, DOM mutations, or URL changes. |

| "This test creates data through the UI because the API setup is complex" | Test data must be created via API or fixtures, not through UI interactions. UI-based setup is slow, brittle, and conflates setup failures with assertion failures. |

| "The test only fails sometimes in CI -- adding a retry will fix it" | Flaky tests block merge. Diagnose the root cause. Retries mask problems. After remediation, rerun 5 times to confirm stability. |

Gates

Escalation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.