CodeceptJS

3.7.8 · active · verified Sun Apr 19

CodeceptJS is an open-source, full-featured End-to-End (E2E) testing framework for Node.js, designed to make acceptance tests human-readable and maintainable. It currently offers a stable version 3.7.8, with version 4.x actively under development as Release Candidates, indicating a continuous release cadence with frequent updates and significant upcoming changes. A key differentiator is its synchronous test syntax, which allows test scenarios to be written linearly without explicit handling of promises or async/await, greatly simplifying test authoring from a user's perspective. It abstracts away the underlying browser automation drivers, supporting various helpers like Playwright, Puppeteer, WebDriver, TestCafe, and Appium, enabling testers to choose their preferred backend while keeping test scripts consistent. This framework focuses on behavioral-driven development (BDD) by providing a natural language API via the `I` object (or `actor`), making tests accessible even to non-technical stakeholders.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a basic CodeceptJS configuration with Playwright and writing two end-to-end scenarios for user authentication, including successful login and an invalid attempt.

import { config } from './codecept.conf';

// codecept.conf.ts (or .js)
// This file defines your CodeceptJS configuration, including helpers.
export const config: CodeceptJS.MainConfig = {
  tests: './*_test.ts',
  output: './output',
  helpers: {
    Playwright: {
      url: 'http://localhost:8080', // Your application's base URL
      show: true,                   // Show browser UI during tests
      browser: 'chromium'           // Specify browser (chromium, firefox, webkit)
    }
  },
  bootstrap: null,
  mocha: {},
  name: 'my-codeceptjs-tests',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: { enabled: true },
    tryTo: { enabled: true },
    screenshotOnFail: { enabled: true }
  }
};

// my_first_test.ts (or .js)
// This file contains your actual test scenarios.
// To run:
// 1. Make sure 'playwright' is installed: `npm i --save-dev playwright`
// 2. Run CodeceptJS: `npx codeceptjs run --steps`

Feature('User Authentication Flow');

Scenario('Verify successful login', async ({ I }) => {
  I.amOnPage('/');
  I.see('Welcome to My App'); // Assert initial text
  I.click('Sign In');
  I.seeCurrentUrlEquals('/login');
  I.fillField('Username', 'testuser');
  I.fillField('Password', 'correctpassword');
  I.click('Login Button');
  I.see('Welcome, testuser!'); // Assert post-login message
  I.seeCurrentUrlEquals('/dashboard');
}).tag('smoke');

Scenario('Verify invalid login attempt', async ({ I }) => {
  I.amOnPage('/login');
  I.fillField('Username', 'invaliduser');
  I.fillField('Password', 'wrongpassword');
  I.click('Login Button');
  I.see('Invalid credentials'); // Assert error message
  I.seeCurrentUrlEquals('/login');
}).tag('negative');

view raw JSON →