Skip to main content
Glama

Playwright IA: Midscene.js

Proyecto de automation con Playwright e inteligencia artificial (Midscene).

  1. Instala dependencias, ejecuta tests y visualiza el reporte para tener un primer vistazo del modo en que opera Midscene.

  2. Configura el MCP Server de Midscene para que automatize lo que le pidas desde un prompt.


📥 Instalación

Instalar dependencias:

npm install
# o
yarn install

Related MCP server: Cloudflare Playwright MCP

▶️ Ejecución de pruebas

Primero exporta tu API_KEY:

#linux
export OPENAI_API_KEY="tu_api_key"

Ejecuta los tests con Playwright y genera un reporte en HTML:

npx playwright test

Si deseas ver el proceso de ejecución:

npx playwright test --headed

📂 Abrir el reporte

Para visualizar el reporte generado, usa el comando:

open midscene_run/report/tu_reporte.html

Se abrirá automáticamente una ventana del navegador con el dashboard de resultados (flujos de MidSceneJS, capturas y trazas).


📂 MidScene: APIs básicas de operación de IA

Usa estas APIs en tus steps para que la IA haga el trabajo.

  • ai o aiAction – Interacción general con IA

  • aiTap – Operación de clic

  • aiHover – Operación de hover (pasar el cursor)

  • aiInput – Operación de entrada de texto

  • aiKeyboardPress – Operación de teclado

  • aiScroll – Operación de desplazamiento

  • aiQuery – Consulta a IA

  • aiAssert – Aserción de IA

  • aiWaitFor – Espera basada en IA

Puedes encontrar más detalles en midscenejs.com/api



🧠 MidScene: MCP Server

Permite usar lenguaje natural para automatizar flujos y generar pruebas con Playwright, utilizando el agente de inteligencia artificial MidScene a través de su MCP Server.


✅ Requisitos

  1. Instala Cursor.

  2. Abre este proyecto con Cursor.

  3. Configura el MCP en Cursor.


⚙️ Configuración del MCP en Cursor

  1. Abre Cursor

  2. Ve a: File > Preferences > Settings

  3. Agrega la siguiente configuración en el apartado MCP:

{
  "mcpServers": {
    "mcp-midscene": {
      "command": "npx",
      "args": ["-y", "@midscene/mcp"],
      "env": {
        "MIDSCENE_MODEL_NAME": "gpt-4o-mini",
        "OPENAI_API_KEY": "<OPENAI_API_KEY>",
        "MCP_SERVER_REQUEST_TIMEOUT": "800000"
      }
    }
  }
}
  1. No olvides ingresar tu OPENAI_API_KEY en el json.


🤖 Enviar prompt en Cursor

Abre un chat en Cursor (Ctrl + N) y escribe tu prompt. Por ejemplo:

Usa el MCP de Midscene para:
1. Open page https://practicetestautomation.com/practice-test-login/ 
2. Type username incorrectUser into Username field
3. Type password Password123 into Password field
4. Push Submit button
5. Verify error message is displayed
6. Verify error message text is Your username is invalid!

Al finalizar:
Crea el test case en Playwright con midscene, en la carpeta e2e con nombre login, usa de ejemplo @sauce-demo.spec.ts 
Exporta OPENAI_API_KEY que esta en @mcp.json 
Ejecuta el test npx playwright test e2e/login.spec.ts --headed

Nota: En el prompt, brinda contexto (ej: "@mcp.json"). De esta manera, Midscene encuentra la información necesaria para cumplir tu solicitud con éxito (templates, API_KEYS, etc).

Available Tools

12 tools
midscene_aiAssertA

Asserts that a specified condition, described in natural language, is true on the page. Polls the condition using AI.

Inputs: assertion (required).

midscene_aiHoverA

Moves the mouse cursor to hover over an element identified by a natural language selector.

Inputs: locate (required).

midscene_aiInputC

Inputs text into a specified form field or element identified by a natural language selector.

Inputs: value (required), locate (required).

midscene_aiKeyboardPressC

Presses a specific key on the keyboard.

Inputs: key (required), locate, deepThink.

midscene_aiScrollC

Scrolls the page or a specified element. Can scroll by a fixed amount or until an edge is reached.

Inputs: direction (required), scrollType, distance, locate, +1 more.

midscene_aiTapC

Locates and clicks an element on the current page based on a natural language description (selector).

Inputs: locate (required).

midscene_aiWaitForA

Waits until a specified condition, described in natural language, becomes true on the page. Polls the condition using AI.

Inputs: assertion (required), timeoutMs, checkIntervalMs.

midscene_get_tabsA

Retrieves a list of all open browser tabs, including their ID, title, and URL.

Inputs: no named parameters.

midscene_navigateA

Navigates the browser to the specified URL. Always opens in the current tab.

Inputs: url (required).

midscene_playwright_exampleC

Provides Playwright code examples for Midscene. If users need to generate Midscene test cases, they can call this method to get sample Midscene Playwright test cases for generating end-user test cases. Each step must first be verified using the mcp method, and then the final test case is generated based on the playwright example according to the steps executed by mcp

Inputs: no named parameters.

midscene_screenshotB

Captures a screenshot of the currently active browser tab and saves it with the given name.

Inputs: name (required).

midscene_set_active_tabA

Switches the browser's focus to the tab specified by its ID. Use midscene_get_tabs first to find the correct tab ID.

Inputs: tabId (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 12 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap. For example, midscene_aiAssert checks conditions, midscene_aiHover hovers over elements, and midscene_aiInput inputs text, all targeting different actions in browser automation. The tools are well-defined and unlikely to cause misselection.

    Naming Consistency5/5

    All tools follow a consistent 'midscene_' prefix and snake_case pattern, with clear verb_noun combinations like aiAssert, aiHover, and get_tabs. This predictability makes it easy for agents to understand and use the toolset without confusion.

    Tool Count5/5

    With 12 tools, the count is well-scoped for browser automation and testing. It covers core actions like navigation, interaction, waiting, and tab management, with each tool earning its place without being excessive or insufficient for the domain.

    Completeness4/5

    The toolset provides comprehensive coverage for browser automation, including navigation, element interaction, condition checking, and tab management. A minor gap is the lack of tools for handling browser contexts or windows, but core workflows are fully supported, allowing agents to perform most common tasks effectively.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers