OpenAI Testing Agent Demo

repository·main·Indexed 20 days ago

https://github.com/openai/openai-testing-agent-demo

A demonstration monorepo for automating frontend testing using OpenAI's Computer Use Agent (CUA) model and Playwright. The system consists of a Next.js frontend for configuring test cases, a Node.js CUA server that orchestrates model interactions and browser actions, and a sample e-commerce application for testing demonstrations.

Tokens
7.5K
Snippets
26
Records
32
Agent score
72%

What's inside openai-testing-agent-demo

  1. Overview of the Testing Agent Demo architecture

    main

    The Testing Agent Demo is a monorepo demonstrating how to automate frontend testing using OpenAI's CUA model and the computer use tool. It uses Playwright to drive a browser instance.

    The system consists of three interconnected components:

    1. frontend: A Next.js web interface used to configure test cases and monitor their execution.
    2. cua-server: A Node.js service that acts as the orchestrator. It communicates with the OpenAI CUA model and uses Playwright to interact with the target web application.
    3. sample-test-app: An example e-commerce site used as the target for testing demonstrations.
  2. Set up the CUA Server

    main

    The CUA Server is a Node.js service that interfaces with the OpenAI CUA model and provides a Socket.IO WebSocket API for the frontend.

    To set up the server:

    1. Create a development environment file from the example:
      cp .env.example .env.development
    2. Open .env.development and add your OPENAI_API_KEY.
    3. Install dependencies and the Playwright browser binaries:
      npm install
      npx playwright install
    4. Start the server:
      npm run dev
      # or
      npm start

    The server listens on port 8000 by default.

    cp .env.example .env.development
    npm install
    npx playwright install
    npm run dev
  3. Customize the testing agent for your own web app

    main

    To use the testing agent with a different web application, you can modify the target URL and the test case. This can be done in two ways:

    1. Via the UI: Use the configuration options provided in the frontend web interface.
    2. Via Code: Update the default values in frontend/lib/constants.ts.

    If you want to integrate the testing agent into your own project, focus on the cua-server package, as it contains the core logic for communicating with the CUA model and driving Playwright.

  4. Configure environment variables in .env.development

    main

    Before starting the development server, you must configure your environment variables. The application uses .env.development for local development.

    Specifically, you must provide an OpenAI key in this file to enable the agent's capabilities.

    cp .env.example .env.development
    # Edit .env.development to include your OpenAI key
  5. Setup the Sample Test App

    main

    The Sample Test App is a Next.js 14 e-commerce demo used as a target for the automated testing agent. To set up the local development environment:

    1. Configure Environment Variables: Copy the example environment file to .env.development and optionally update ADMIN_USERNAME and ADMIN_PASSWORD.
    2. Sync Credentials: If you change the admin credentials in the .env.development file, you must also update them in the frontend configuration (the default values are located in frontend/lib/constants.ts).
    3. Install and Run: Install dependencies via npm and start the development server.

    The application runs at http://localhost:3005.

    # 1. Copy environment file
    cp .env.example .env.development
    
    # 2. Install dependencies and start dev server
    npm install
    npm run dev
  6. Set up the Frontend UI

    main

    The Frontend UI is a Next.js application that serves as the web interface for the Testing Agent demo. It enables users to define test cases, transmit them to the CUA server, and visualize messages from the CUA model.

    To run the frontend, you must ensure the CUA server is running and, for a complete demo experience, the sample-test-app is also active.

    Prerequisites

    • A running CUA server.
    • A running sample-test-app (optional, for demo purposes).
    # 1. Prepare environment variables
    cp .env.example .env.development
    # (Manually edit .env.development to add your OpenAI key)
    
    # 2. Install dependencies
    npm install
    
    # 3. Start the development server
    npm run dev
  7. Setup and run the Testing Agent Demo

    main

    Follow these steps to clone, configure, and run the full demo environment locally.

    1. Clone the repository

    git clone https://github.com/openai/openai-testing-agent-demo
    cd openai-testing-agent-demo

    2. Configure environment variables

    You must provide an OPENAI_API_KEY. Create .env.development files for each package by copying the examples:

    cp frontend/.env.example frontend/.env.development
    cp cua-server/.env.example cua-server/.env.development
    cp sample-test-app/.env.example sample-test-app/.env.development

    Note on Sample App Credentials: The sample-test-app requires demo login credentials in its .env.development file. By default, these are:

    • ADMIN_USERNAME=test_user_name
    • ADMIN_PASSWORD=test_password

    3. Install dependencies

    npm install
    npx playwright install

    4. Run the application

    npm run dev

    Once running, the services are available at:

    git clone https://github.com/openai/openai-testing-agent-demo
    cd openai-testing-agent-demo
    
    # Prepare env files
    cp frontend/.env.example frontend/.env.development
    cp cua-server/.env.example cua-server/.env.development
    cp sample-test-app/.env.example sample-test-app/.env.development
    
    # Install and run
    npm install
    npx playwright install
    npm run dev
  8. Security warnings for Computer Use

    main

    Caution

    Computer use is currently in preview. Because the model is in preview, it may be susceptible to exploits or inadvertent mistakes.

    Best Practices:

    • Use this project in test environments only.
    • Do not use real user data in production.
    • Avoid trusting the agent in authenticated environments or for high-stakes tasks.
  9. Configure frontend environment variables

    main

    The frontend requires an OpenAI API key to function. You can also optionally configure the browser's viewport dimensions and provide environment-specific instructions to guide the testing agent's behavior (e.g., specifying the operating system or keyboard modifier keys).

    OPENAI_API_KEY=your-openai-key
    
    # Optional: Set the display size for the browser.
    DISPLAY_WIDTH=1024
    DISPLAY_HEIGHT=768
    
    # Optional: Add any environment specific instructions here.
    ENV_SPECIFIC_INSTRUCTIONS="This is MacOS, so use CMD key for actions that are typically done with Control key on Windows."
  10. Configure viewport dimensions via environment variables

    main

    The cuaLoopHandler determines the browser viewport size using the following environment variables. If these are not set, the handler defaults to 1024x768.

    • DISPLAY_WIDTH: The width of the browser viewport (integer).
    • DISPLAY_HEIGHT: The height of the browser viewport (integer).
    # Example setting dimensions in a shell environment
    export DISPLAY_WIDTH=1920
    export DISPLAY_HEIGHT=1080