Sahi Documentation

TypeScript Support

abstract Sahi allows scripts to be written in TypeScript. TypeScript .ts files need to be first compiled to JS and then executed via Sahi.
warning This is an advanced customization and should be used only when you absolutely need to use TypeScript. Sahi's editor etc. do not have native support for TypeScript.

Pre-requisites

  1. Node.js must be installed in the system.
  2. TypeScript must be installed in the system.

Building TypeScript

  1. Copy <SahiPro>/userdata/scripts/sahitests/typescript/sahi_apis.ts file in your TypeScript workspace.
  2. Create tsconfig.json in your workspace, if not exist and put the following contents
    {
        "compileOnSave": true,
        "compilerOptions": {
            "target": "es3",
            "outDir": "<SahiPro>/userdata/scripts/sahitests/typescript/out"
        }
    }
    infoNOTE: Replace <SahiPro> with the Sahi Pro installation directory. Target should be es3
  3. Open the TypeScript workspace in MS Code and build the project.
    Go to: Tasks -> Run Build Task -> tsc:build
    Or,

    Open a command prompt/bash, cd to TypeScript workspace and run tsc.
  4. It will build the TypeScript workspace and create JavaScript files in <SahiPro>/userdata/scripts/sahitests/typescript/out directory.
  5. Open the JavaScript files in Sahi Pro Editor and run the script.