Skip to content

Testing: Self-Healing QA

Goal: Move from “Manual Testing” or “Brittle Automation” to Resilient, AI-Generated Quality Assurance. We use AI to write the tests, and AI to fix them when they break.

graph LR
    Code[New Feat Code] -->|Analyze| AI[QA Copilot]
    AI -->|Generate| Test[Test Case List]
    Test -->|Generate| Script[Playwright Script]
    Script -->|Run| Pipeline[CI Pipeline]
    
    Pipeline -->|"Fail (UI Change)"| Heal[Self-Healing Agent]
    Heal -->|Analyze DOM| Script
    Heal -->|Retry| Pipeline
    
    style AI fill:#fff9c4
    style Heal fill:#c8e6c9
    style Pipeline fill:#ffccbc
  • Frameworks: Playwright (preferred over Selenium), Cypress.
  • AI Integration: Copilot for tests, ZeroStep AI (AI assertions).
  • Reporting: Allure Report (for visualizing failures).
  • Data: Synthetic data generators (faker.js via LLM).
  1. Generate Test Cases: Before scripting, feed the User Story to the AI.
  2. Scaffold the Script: Ask AI to write the Playwright boilerplate.
  3. Visual Regression: Use AI to compare screenshots (e.g., “Is the layout broken?” vs “Did the pixel move 1px?”).
  4. Self-Healing Setup: Implement a mechanism where, if a selector fails (e.g., #submit-btn became #btn-submit), the AI suggests a fix based on the DOM dump.

Input:

“User Story: VIP Checkout. User clicks ‘Buy’, sees discount, enters CC, clicks Pay.”

Prompt:

“Generate 5 critical test cases for the VIP Checkout story, including negative cases.”

AI Output:

  1. Verify VIP user gets 5% discount.
  2. Verify Non-VIP user gets 0% discount.
  3. Verify payment fails with invalid card number.
  4. Verify error message if API is down.
  5. Verify total calculation with tax.

Prompt:

“Write a Playwright test for Case 1. Use Page Object Model.”

AI Output:

test('VIP User receives discount', async ({ page }) => {
const checkout = new CheckoutPage(page);
await checkout.loginAs('vip_user');
await checkout.addItem('item-123'); // Price: $100
await expect(checkout.totalLabel).toHaveText('$95.00'); // 5% off
});

Scenario: The developer changed the ID of the total label from #total-lbl to #summary-total. The test fails.

Visual AI Assertions (ZeroStep style): Instead of rigid selectors, use AI instructions:

// Traditional (Brittle)
await page.locator('#total-lbl').textContent();
// AI-Driven (Resilient)
await ai('Verify that the total price shown is $95.00');

The AI looks at the visible page text, ignoring the underlying ID change.

  • Page Object Model: Always ask the AI to use POM. It keeps code clean.
  • Synthetic Data: Don’t use real PII. Ask AI: “Generate a JSON of 10 fake users with realistic addresses.”
  • Flakiness: If AI writes a flaky test (one that fails randomly), ask it to “Add retry logic or waits to make this robust.”

False Positives

Visual AI testing (e.g., “Does this look right?”) might say “Yes” even if a critical button is slightly obscured. Combine with functional assertions.

  1. Maintenance is Key: AI reduces the cost of writing tests, but Self-Healing reduces the cost of maintaining them.
  2. Selectors Matter: AI is great at finding robust selectors (e.g., getByText('Submit')) vs brittle XPath.
  3. Shift Left: Generate the tests simultaneously with the code.