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.
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.
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. In the New Test Script dialog, specify the file name and extension (
.js
or.ts
), and click Create.TestCafe Studio creates the file with a test script template and opens it in the Code Editor.
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.
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:
Invoke the context menu for a recorded test or fixture in the Explorer Panel and select Convert to JavaScript Code.
Open a test in the Test Editor and click Convert to JavaScript Code on the toolbar.
Open a fixture in the Fixture Editor and click Convert to JavaScript Code on the toolbar.
This invokes the Convert to JavaScript dialog. Specify the file name and extension, then click Create.