PRODUCTION/
Developer Reference• TraceKit Engine v0.1

Technical Documentation

Comprehensive architecture and capability guide for TraceKit's autonomous testing engine, locator resolution hierarchy, deterministic assertion protocols, and failure diagnosis rules.

Architecture

1. Overview

TraceKit is an autonomous browser testing agent designed to eliminate selector maintenance and fragile test scripts. Rather than relying on rigid XPath or CSS selector paths that break on DOM updates, TraceKit translates high-level natural language test goals into resilient, multi-step browser actions powered by multimodal LLM reasoning and verified by deterministic Chromium assertions.

Acts

Inspects accessibility trees, clicks, types, selects, scrolls, and navigates.

Verifies

Validates page state via 11 deterministic browser assertions directly against Chromium.

Explains

Automated failure diagnosis categorizes root causes into application crashes vs automation failures.

Execution Loop

2. How TraceKit Works

Each test run executes inside an isolated Patchright/Chromium browser context using a 5-stage continuous execution cycle:

1. OBSERVE

Captures clean DOM accessibility snapshots, visible element labels, interactive controls, current URL, and viewport screenshot.

2. REASON

The LLM reasoning engine assesses current page state against the test goal and previous actions, deciding the next single discrete action.

3. ACT

ActionDispatcher resolves target elements through the 6-tier locator ladder and performs the physical browser action.

4. VERIFY

Deterministic assertions evaluate element visibility, values, text, or counts directly via Playwright assertions before proceeding.

5. REPORT

Compiles chronological step traces, full-resolution screenshot galleries, execution timings, and deterministic diagnosis reports.

Action Protocol

3. Agent Actions

The agent communicates decisions via a strict discriminated Pydantic action schema supported by the backend:

Action TypeKey ParametersDescription
clickrole, name, text, index, button, click_countClicks on a target element with single or multi-click support.
fillvalue, role, name, placeholder, label, selectorFocuses and types text into input fields or textareas.
navigateurl (http/https)Navigates the browser page to a new web location.
assertassertion_type, expected_value, locator criteriaExecutes a deterministic Playwright assertion.
press_keykey (Enter, Escape, Tab, ArrowDown, ArrowUp, Backspace)Sends a keyboard keypress event to the page or active element.
selectvalue or label, locator criteriaSelects an option inside a native HTML <select> dropdown.
scrolldirection ('down' | 'up'), amount (px)Scrolls the viewport up or down by a specified pixel distance.
hoverlocator criteriaHovers over an element to trigger dropdowns or tooltip states.
finishsuccess (boolean), message (string)Terminates the test run signaling goal fulfillment or blocker.
Resolution Ladder

4. Locator Priority Ladder

TraceKit generally prefers accessible locators (such as role/name, text, placeholder, and label) to avoid brittle test scripts. However, when an explicit selector is provided, selector resolution takes precedence in execution:

  1. CSS Selector / data-testid: (e.g. selector="[data-test='login-button']") — takes precedence whenever explicitly provided.
  2. Role + Accessible Name: (e.g. role="button", name="Add to cart") — preferred accessibility locator.
  3. Exact or Partial Text: (e.g. text="Checkout") — matches visible rendered strings.
  4. Placeholder Attribute: (e.g. placeholder="Enter your email") — ideal for search and text inputs.
  5. Associated Label: (e.g. label="Password") — resolves inputs via associated form <label> tags.
  6. Disambiguation Index: (e.g. index=0) — 0-based integer to disambiguate and select an exact element when multiple matching elements are found.
Verification Protocol

5. Deterministic Assertions

Unlike subjective LLM judgments, TraceKit verifies test conditions directly against Chromium DOM APIs using Playwright's expect assertion library:

visible / hidden

Verifies whether an element is present and visible in the viewport, or completely detached/hidden.

has_text / has_value

Verifies that an element contains expected text or that a form input holds an expected value.

has_url / has_title

Page-level assertions verifying that the browser URL or document title matches the expected string.

enabled / disabled

Checks interactive states for submit buttons, links, and form controls.

checked / unchecked

Verifies the checked state of HTML checkboxes and radio button toggles.

has_count

Verifies that a locator matches an exact non-negative integer count of elements (e.g. cart badge count or list item quantity).

Inference Layer

6. LLM Reasoning Providers

TraceKit supports multiple reasoning providers configured through environment variables or Test Studio advanced options:

Google Gemini (Default)gemini-3.6-flash

Primary reasoning provider. Also supports curated models: gemini-2.5-flash, gemini-2.5-pro.

Groqopenai/gpt-oss-120b

Ultra-low latency LPU inference. Also supports curated models: openai/gpt-oss-20b, qwen/qwen3.6-27b.

Ollamaqwen2.5-coder:3b

Self-hosted, air-gapped local model execution. Also supports curated model: llama3.2:3b.

Auto Fallback OrchestratorPriority Cascade

Attempts primary configured provider and gracefully cascades to alternate available backends upon rate limits (HTTP 429) or transient network timeouts.

Session Injection

7. Session & Storage State

TraceKit supports testing post-login flows without repeating the login sequence on every test execution. Users can supply Playwright-compatible storage_state JSON in the Advanced Settings drawer:

{
  "cookies": [
    {
      "name": "session_token",
      "value": "xyz...",
      "domain": ".example.com",
      "path": "/",
      "httpOnly": true,
      "secure": true
    }
  ],
  "origins": [
    {
      "origin": "https://example.com",
      "localStorage": [{ "name": "user_id", "value": "1001" }]
    }
  ]
}

When provided, the browser context initializes with these injected cookies and local storage tokens, immediately loading authenticated dashboards or checkout flows.

Root Cause Analysis

8. Failure Diagnosis Engine

When a test run finishes with failure, the backend diagnosis engine (diagnosis.py) categorizes the failure into two major classes and pinpoint causes:

APPLICATION_BEHAVIOR_MISMATCH

The application under test failed or behaved unexpectedly.

  • APPLICATION_CRASH: Target website threw uncaught JavaScript exceptions or returned HTTP 5xx server errors.
  • ASSERTION_FAILED: A deterministic assertion failed (e.g. checkout button was disabled, item count mismatched).
  • EXPECTED_STATE_NOT_REACHED: Target condition could not be fulfilled within the step budget.
AUTOMATION_FAILURE

An environmental, provider, or locator issue halted test automation.

  • NAVIGATION_ERROR: Target URL failed DNS resolution, connection refused, or timed out.
  • PROVIDER_ERROR: LLM reasoning provider threw an unrecoverable exception or rate limit.
  • SESSION_ERROR: Browser session launch failure or headless crash.
  • LOCATOR_NOT_FOUND: Target locator criteria could not match any DOM element.
  • BUDGET_EXCEEDED: Max step count exhausted before reaching test conclusion.
Inspectable Evidence

9. Reports & Artifacts

Every test run produces complete, inspectable evidence packages persisted to the backend artifacts directory:

report.json

Machine-readable JSON containing full step timestamps, actions, locator strategies, and raw LLM reasoning outputs.

report.md

Human-readable GitHub-flavored Markdown report detailing objectives, step logs, assertions, and final verdict.

trace.zip

Standard Playwright execution trace file viewable in trace.playwright.dev with full DOM snapshots and timeline scrubbers.

screenshots/

Timestamped full-resolution PNG visual evidence captures recorded before and after each browser interaction.

Walkthrough

10. Example Workflow

Here is a realistic end-to-end execution trace demonstrating autonomous e-commerce checkout verification on Saucedemo:

# Test Objective: "Log in with standard_user, add the backpack to the cart, and verify the checkout button is enabled."
Step 1: navigate(url="https://www.saucedemo.com") → 200 OK (312ms)
Step 2: fill(placeholder="Username", value="standard_user") → resolved via placeholder (48ms)
Step 3: fill(placeholder="Password", value="secret_sauce") → resolved via placeholder (44ms)
Step 4: click(role="button", name="Login") → resolved via role+name (185ms)
Step 5: click(selector="[data-test='add-to-cart-sauce-labs-backpack']") → resolved (76ms)
Step 6: click(role="link", name="Shopping Cart") → resolved via role+name (120ms)
Step 7: assert(assertion_type="enabled", role="button", name="Checkout") → PASSED (32ms)
Step 8: finish(success=true, message="Checkout button is verified enabled after adding backpack.")