Use the Documentation link to view help for this action.
Write the Script
Scripts in the Run TestCafe Script action can use TestCafe API, Node.js core and third-party modules.
TestCafe executes this script in the server-side test runner. The DOM, browser API and client-side objects are not available in its context. Use client functions and selectors to obtain data from the DOM.
TestCafe executes the script as an asynchronous function. Add await to all asynchronous calls.
TestCafe executes custom scripts as parts of the current test. You cannot use them to declare new tests or fixtures.
The Visual Test Recorder cannot synchronize the browsing context with Run TestCafe Script action's code.
For instance, consider a test with a custom script that uses t.switchToIframe to switch the browsing context. If you try to record new actions in this test, the Recorder does not detect that the context has changed and continues recording in the main window.
To avoid this, do not switch the browsing context in custom scripts. Use the Switch Frames actions instead.
Import Node.js Modules
You can import Node.js modules (including core modules) to the Run TestCafe Script action's code with the require function.
Click the Run script button to execute the script during recording.
You cannot run a script when a different script is executed, or an assertion is evaluated.
You can use the Run script button to debug scripts in a hook when the Recorder stops inside this hook because of a failed action or error. In this instance, you cannot run scripts in the test until the Recorder completes playing back the hook.
The Run script button runs the custom script against the tested page in its current state, as it is displayed in the browser.
Print Debug Information
TestCafe Studio intercepts console output in the script and prints it in the action's parameters area.