CodeceptJS Documentation

website·Indexed 35 days ago

https://codecept.io/

An open-source end-to-end testing framework for JavaScript. It supports multiple helpers including Playwright, WebDriver, and Puppeteer, and provides features like Page Objects, visual testing, self-healing tests with AI, and a graphical test runner called CodeceptUI. It includes support for TypeScript, React Native, and a Model Context Protocol (MCP) server for AI agents.

Tokens
230.9K
Snippets
1.6K
Records
1.9K
Agent score
67%

What's inside CodeceptJS

  1. Overview of CodeceptJS AI capabilities

    CodeceptJS integrates AI providers (such as OpenAI, Anthropic, and Google) to act as a testing co-pilot. It improves automated testing by sharing the current page's HTML context (minified and stripped of non-interactive elements) with the LLM to generate semantic locators and suggest fixes. Key capabilities include:

    • Assisting in writing tests during pause() or interactive shell mode.
    • Self-healing failing tests on CI by identifying new locators for changed elements.
    • Analyzing test failures to provide detailed explanations and suggested fixes.
  2. Overview of GraphQLDataFactory

    GraphQLDataFactory is a CodeceptJS helper used to manage remote data via GraphQL queries. It integrates with data generators like Rosie or Factory Girl to define rules for creating test records. These records are saved to the server via GraphQL mutations and are automatically deleted at the end of the test to ensure a clean state.
  3. Overview of ApiDataFactory

    ApiDataFactory is a CodeceptJS helper used to manage remote data via a REST API. It integrates with data generators like Rosie or Factory Girl to define rules for generating test records. These records are created via API requests before tests and are automatically deleted after the test completes to ensure a clean environment.
  4. Overview of the CodeceptJS auth plugin

    The auth plugin logs a user in for the first test and reuses the session for subsequent tests by saving cookies in memory or to a file. If a session expires, the plugin automatically performs the login process again. This is particularly useful for improving development experience and test execution speed.
  5. Overview of CodeceptJS Healing

    Healing is a mechanism that defines how a test reacts to a failure. Instead of simply failing or retrying the entire test, healing recipes can perform specific actions on the fly (e.g., navigating to a login page if unauthorized) to fix the state and continue execution. Unlike retries, healing is declarative, can perform a wide set of custom actions, and can react to any step of any test without modifying the test code itself.
  6. Overview of CodeceptJS locator types

    CodeceptJS uses locators to identify DOM elements for actions like click, fillField, see, and waitForVisible. Locators come in two primary forms:

    1. Strict locators: Objects with a specific strategy key (e.g., { css: 'button' }, { role: 'button', name: 'Submit' }, { xpath: '//td[1]' }, { id: 'email' }). These ensure the helper runs exactly one specific query.
    2. Semantic locators: Plain strings (e.g., 'Sign In', 'Email') that match labels, button text, placeholders, and aria-* attributes, mimicking how a human reads a page.

    Supported strategies include: css, xpath, id, name, role, frame, shadow, and pw (for Playwright-specific locators).

  7. Overview of Explorbot self-driving tests

    Explorbot is an AI agent that automates the creation of end-to-end tests. By pointing it at a URL, the agent explores the application, plans scenarios (including happy paths and edge cases), executes them in a browser, and saves the successful flows as CodeceptJS tests. It operates via a five-step process: Research (mapping the page), Plan (drafting scenarios), Execute (driving the browser), Verify (confirming outcomes), and Keep (saving passing flows as tests).
  8. Overview of CodeceptJS MCP Server

    The Model Context Protocol (MCP) server for CodeceptJS enables AI agents to drive a browser session in-process. It allows agents to list tests, execute arbitrary I.* code, pause/poke through scenarios, capture artifacts, and read aiTrace markdown while sharing a single browser and container.
  9. Overview of CodeceptJS Architecture

    CodeceptJS is a BDD-style end-to-end testing framework where tests are written as linear user scenarios. It uses an 'actor' object (represented as I) which acts as a proxy for configured Helpers. CodeceptJS does not execute actions directly; instead, it delegates all test commands to a helper backend. This allows developers to switch automation engines without rewriting tests, although some backend-specific features may vary.

    Supported Helpers include:

    • Playwright: Chromium, Firefox, WebKit automation
    • WebDriver: Native browser automation via WebDriver Protocol
    • Appium: Mobile testing on iOS/Android
    • Puppeteer: Chromium automation via DevTools Protocol
  10. Overview of Kitesurf cloud browser helper

    Kitesurf is a cloud browser helper that extends CDPBrowser to run tests against Cloudflare’s Browser Run service. It automates real browser sessions within Cloudflare’s cloud infrastructure, removing the requirement to manage local browser instances. It is currently in Beta.
  11. Overview of Explorbot self-driving tests

    Explorbot is an AI agent built by the CodeceptJS team that automates the creation of end-to-end tests. It explores a target URL, plans test scenarios (including happy paths and edge cases), executes them in a browser, and saves the passing flows as CodeceptJS tests. It is designed to complement existing regression suites by discovering paths and UI interactions that manual scripts might miss.
  12. Overview of the CodeceptJS els module

    The els module provides low-level element manipulation functions for CodeceptJS tests, offering granular control over interactions and assertions. It wraps elements in a unified WebElement class, ensuring a consistent API regardless of the underlying helper used (Playwright, WebDriver, or Puppeteer). These functions require a helper that implements the _locate method to be enabled.
    import { element, eachElement, expectElement, expectAnyElement, expectAllElements } from 'codeceptjs/els'