Skip to main content
A newer version of this page is available. .

Test Scripts

  • 2 minutes to read

TestCafe Studio provides API that allows you to write tests in JavaScript, TypeScript or CoffeeScript. You can create a test script file in the test directory and write test code in a built-in Code Editor.

A test script file can contain several tests that are organized by fixture. The Explorer panel displays these tests as the file's children. Fixture names are shown above the test list.

Test scripts

You can also convert recorded tests to test script files.

NOTE

TestCafe Studio also allows you to use tests created in earlier TestCafe versions (.test.js files). You can add these files to a test directory and view/modify/run the tests in TestCafe Studio.

Write a Test Script

Follow the steps below to write test script from scratch.

  1. Create a test script file in a test directory or subdirectory. Select the directory in the Explorer panel, invoke the context menu, and select New Test Script button New Test Script. In the New Test Script dialog, specify the file name and extension (.js or .ts), and click Create.

    New Test Script dialog

    TestCafe Studio creates the file with a test script template and opens it in the Code Editor.

    Test Script Template

  2. Edit the test script template: modify the fixture's name, the test's name, specify a tested page's URL, and add the test code to the test function. See the Test API topic in the open-source TestCafe documentation for information about the API used in tests.

    Write Test Script

Convert Recorded Tests to JavaScript

You can convert recorded tests to JavaScript to get more flexibility and use all the features of TestCafe JavaScript API.

To convert a test or fixture, do any of the following:

This invokes the Convert to JavaScript dialog. Specify the file name and extension, then click Create.

Convert to JavaScript Code Dialog