In addition to writing Custom validations and actions scripts (which execute in the browser run-time environment), you can also create custom Node.js scripts that will be executed in your CLI environment.
These scripts will be executed from inside a test with context just like a standard custom action. It opens the gateway for some very advanced actions such as database validation and manipulation, image and PDF validations, and many more (see usage examples below).
You can create a CLI action step just like you would create a normal custom action and validation.
When running locally (as opposed to running from the CLI) we need to provide the CLI action steps a Node.js environment in which to execute the code in.;
When you try to locally run a test which contains a CLI action step, you will be asked to provide this runtime environment. To do this, simple execute the following command from your shell:
npm i -g @testim/testim-cli && testim --agent
Executing Node.js scripts from inside the context of a test is great, but the real power of CLI actions comes from the ability to add any node package directly from npm (or any other source) and have those packages scoped to the CLI action step during test execution.
We support all the standard methods for defining packages dependencies. Visit this page for more information about the various options and syntax.
To run async code in the CLI action you have to return the promise you wish to resolve.
Without returning it, the step will run synchronously and will resolve when the last line of code is executed, regardless of the expected results.
This is an advanced feature, to enable it please reach out via our chat or contact your CSM.
Updated 17 days ago