Skip to content

Quickstart

Install CodeceptJS into your project:

npm install codeceptjs playwright --save-dev

Then install the browser binaries:

npx playwright install --with-deps

The --with-deps flag also installs required system dependencies for the browsers.

Prefer WebDriver or Appium? See installation options for all supported helpers.


Initialize CodeceptJS to set up the config file and test directory:

npx codeceptjs init

This command walks you through a short setup wizard and creates codecept.conf.js, a sample test file, and any required browser binaries.

Answer the questions, accepting defaults to get started quickly:

QuestionDefault AnswerAlternative
Do you plan to write tests in TypeScript?n (No)or learn how to use TypeScript
Where are your tests located?**./*_test.jsor any glob pattern like **.spec.js
What helpers do you want to use?PlaywrightSee options for web testing, mobile testing, API testing
Where should logs, screenshots, and reports be stored?./outputpath to store artifacts and temporary files

For Playwright, you’ll also be asked about the site and browser:

QuestionDefault AnswerAlternative
Base url of site to be testedhttp://localhostURL of the site you plan to test
Show browser windowy Yesor run in headless mode
Browserchromiumor firefox, webkit (open-source Safari), or electron

Sample output:

? Do you plan to write tests in TypeScript? No
? Where are your tests located? **./*_test.js
? What helpers do you want to use? Playwright
? Where should logs, screenshots, and reports be stored? ./output
? [Playwright] Base url of site to be tested http://localhost
? [Playwright] Show browser window Yes
? [Playwright] Browser in which testing will be performed chromium

When asked, create your first feature and test file.


Open the generated test file. It will look like this:

Feature('My First Test');
Scenario('test something', ({ I }) => {
});

Add a simple scenario:

Feature('My First Test');
Scenario('test something', ({ I }) => {
I.amOnPage('https://github.com');
I.see('GitHub');
});

npx codeceptjs run

Expected output:

Terminal window
My First Test --
test something
I am on page "https://github.com"
I see "GitHub"
OK

Run in headless mode:

npx codeceptjs run --headless

See all available commands in the CLI reference.

▶ Next: CodeceptJS Basics