passmark

repository·main·Indexed 22 days ago

https://github.com/bug0inc/passmark

An open-source AI framework for browser regression testing built as a Playwright library. It enables the creation of stable, auto-healing tests using natural language steps, multi-model consensus assertions, and intelligent Redis caching. Features include support for OpenAI's Computer-Use Agent (CUA) mode, video assertions for transient UI elements, and a placeholder system for dynamic data injection.

Tokens
15.6K
Snippets
35
Records
82
Agent score
78%

What's inside passmark

  1. Configure and troubleshoot CUA mode

    main

    CUA mode (mode: "cua") uses OpenAI's Responses API directly with the computer tool. This mode has specific requirements:

    • Gateway Restriction: CUA does not work through gateways (Vercel, OpenRouter, Cloudflare). You must set gateway: "none" in your configuration.
    • Required Key: OPENAI_API_KEY must be set in your environment.
    • Access Issues: If you receive a 400 error with param: null, verify your OpenAI organization has access to the CUA model and the computer tool on the Responses API.
    • Tool Compatibility: If you see errors regarding computer_use_preview, you are likely on an old build. The current API uses { type: "computer" }. Rebuild from main to resolve.
  2. Using the Placeholder System for dynamic data

    main

    Passmark provides a placeholder system to inject dynamic values into step data. These can be scoped to a single test or shared globally across an execution.

    PatternScopeDescription
    {{run.email}}Single testRandom email (faker)
    {{run.dynamicEmail}}Single testEmail using configured domain
    {{run.fullName}}Single testRandom full name
    {{run.shortid}}Single testRandom short unique ID
    {{run.phoneNumber}}Single testRandom phone number
    {{global.email}}All tests in an executionShared across runSteps calls with same executionId
    {{global.dynamicEmail}}All tests in an executionShared dynamic email
    {{data.key}}Per projectStored in Redis, managed via project settings
    {{email.type:prompt}}Resolved lazilyExtract content from received email
  3. Use OpenAI Computer-Use Agent (CUA) mode

    main

    By default, Passmark uses ARIA accessibility snapshots. For visual, screenshot-driven automation using OpenAI's computer-use agent, configure the mode to "cua".

    Requirements & Limitations:

    • Requires gateway: "none" (CUA requires direct OpenAI access).
    • Requires OPENAI_API_KEY in your .env.
    • The CUA model (gpt-5.5 + computer tool) is currently locked and not user-configurable.
    • Redis step caching is skipped in CUA mode.
    • Not compatible with vercel, openrouter, or cloudflare gateways.
    import { configure } from "passmark";
    
    configure({
      ai: {
        mode: "cua",
        gateway: "none", // CUA requires direct OpenAI access
      },
    });
  4. Perform hybrid runs with per-step AI overrides

    main

    You can mix cheap, cacheable snapshot-based steps (via gateways like OpenRouter) with visual CUA steps in a single runSteps or runUserFlow call.

    Precedence: step.ai > call-level ai > global configure().

    To use a CUA step within a snapshot-based run, set ai: { mode: "cua", gateway: "none" } on that specific step. Note that OPENAI_API_KEY must still be provided.

    configure({ ai: { gateway: "openrouter" } }); // most steps go through OpenRouter
    
    await runSteps({
      page,
      test,
      expect,
      userFlow: "Buy product on sale",
      steps: [
        { description: "Navigate to /products" },                     // OpenRouter snapshot
        {
          description: "Drag the price slider to $40",
          ai: { mode: "cua", gateway: "none" },               // CUA for this step only
        },
        { description: "Click Add to cart" },                         // back to OpenRouter snapshot
      ],
    });
  5. How step caching works in Passmark

    main

    Passmark uses Redis to cache successful step actions. On subsequent runs, cached steps execute directly without AI calls, reducing latency and cost.

    Key Details:

    • Steps are cached by userFlow + step.description.
    • To force AI execution, set bypassCache: true on individual steps or the entire run.
    • Cache is automatically bypassed on Playwright retries.
    • Limitation: Currently, only single-step AI executions are cached; multi-step actions are not yet cached.
  6. Configure Passmark settings

    main

    Call configure() once before executing any core functions to set up AI gateways, models, and upload paths.

    import { configure } from "passmark";
    
    configure({
      ai: {
        gateway: "none", // "none" (default), "vercel", "openrouter", "opencodezen", or "cloudflare"
        models: {
          stepExecution: "google/gemini-3-flash",
          utility: "google/gemini-2.5-flash",
        },
      },
      uploadBasePath: "./uploads",
    });
  7. Install Passmark in a Playwright project

    main

    To use Passmark, initialize a Playwright project and install the passmark package. It is recommended to use TypeScript.

    npm init playwright@latest passmark-project # select the default options and set language to TypeScript
    cd passmark-project
    npm install passmark
    npm init playwright@latest passmark-project
    cd passmark-project
    npm install passmark
  8. Configure email providers for testing

    main

    To test flows involving email verification, configure an email provider. You can use the built-in emailsink provider or implement a custom one.

    Using emailsink:

    import { configure } from "passmark";
    import { emailsinkProvider } from "passmark/providers/emailsink";
    
    configure({
      email: emailsinkProvider({ apiKey: process.env.EMAILSINK_API_KEY }),
    });

    Custom Provider Example:

    configure({
      email: {
        domain: "my-test-mail.com",
        extractContent: async ({ email, prompt }) => {
          // Fetch and extract content from your email service
          return extractedValue;
        },
      },
    });

    Usage in steps: Use the {{email.type:prompt}} pattern to extract data:

    { 
      description: "Enter the verification code", 
      data: { value: "{{email.otp:get the 6 digit verification code:{{run.dynamicEmail}}}}" } 
    }
  9. Set up dotenv in Playwright configuration

    main

    To ensure your Playwright tests can read the .env file containing your API keys, add the following to your playwright.config.ts file. You must first install dotenv via npm install dotenv.

    import dotenv from 'dotenv';
    import path from 'path';
    
    dotenv.config({ path: path.resolve(__dirname, '.env') });
  10. Quick checklist for Passmark setup

    main

    Before running Passmark, ensure your environment meets these requirements:

    • Node.js: version 18 or higher.
    • Dependencies: Install via pnpm install (or npm install).
    • Browsers: Install Playwright browsers using npx playwright install.
    • Redis: Must be available at the REDIS_URL or configured via configure({ redis: { url } }).
    • AI API Keys:
      • For direct providers: ANTHROPIC_API_KEY or GOOGLE_GENERATIVE_AI_API_KEY.
      • For Vercel AI Gateway: AI_GATEWAY_API_KEY.
      • For CUA mode (mode: "cua"): OPENAI_API_KEY and gateway: "none".
  11. Configure AI providers and API keys

    main

    Passmark requires API keys to call model providers. You can set these via environment variables or through the configure function.

    Direct Provider Usage

    Set the following environment variables:

    export ANTHROPIC_API_KEY=sk-...
    export GOOGLE_GENERATIVE_AI_API_KEY=AIza...

    Vercel AI Gateway

    To use the Vercel AI Gateway, call configure({ ai: { gateway: 'vercel' } }) and set the required key:

    export AI_GATEWAY_API_KEY=your_gateway_key