typescriptcodeceptjs

How can we use Typescript with CodeceptJS for testing framework?


I have to create a testing framework using CodeceptJS. I am trying to use typescript instead of javascript to write my page objects and tests. Can someone help with what configuration is required in conf.js or steps.ts file

I have added below in conf file but not sure what else to add require: ["ts-node/register", "should"]


Solution

    1. Add package ts-node to your package.json dev dependencies. And install dependencies
    2. Add require: ["ts-node/register"] to config.
    3. Make sure, your tests regexp in configuration supports ts files: for example tests: "./tests/*.spec.ts"

    Definitions for codeceptjs are generated by command codeceptjs def. https://codecept.io/commands#typescript-definitions

    You should add this definitions in your tsconfig.

    P.S. There are an example for TS&CodeceptJS integration: https://github.com/elukoyanov/codecept-typescript-example

    Pay attention, it has one tsconfig for main project (in project directory) and second tsconfig for codeceptjs only (in src/specs/e2e path)