exec() returns the commandโs output.
- On Linux sandboxes, use
'sh'. The command runs in Bash. - On Windows sandboxes, use
'pwsh'. The command runs in PowerShell.
Signature
Parameters
ExecOptions
required
cd or an environment variable you set carries over to the next exec() call.
Returns
Promise<string>. The commandโs standard output, with leading and trailing whitespace trimmed. Output over 5 MB is cut off.
Errors
exec() throws when:
- The command exits with a non-zero code. The message is
Command failed with exit code <code>: <stderr>. - The command runs longer than
timeout.
Examples
Create a file the test needs
Read a value and check it
Install software on Windows
Launch an app on Windows
provision instead. It launches the app and waits for it.
Positional form
Older tests pass the options as arguments:language: 'js' is also accepted. It runs the code in Node on your own machine, not in the sandbox, and returns the value you assign to a result variable. Write the JavaScript directly in your test instead.Complete example
tests/download.test.mjs
Related
- Launch apps: open Chrome, VS Code, and installers
- focusApplication(): bring a launched app to the front
- Customize devices: set up the sandbox before your test

