Quite often there is a need to validate the content of a downloaded document which could be a PDF, Word Document, CSV file or databases such as MySQL, MongoDB. All these are possible within Testim using the CLI action step. This feature helps to create and execute custom Node.js scripts at runtime; to perform different validations. Below are some tips to help with CLI action steps.
Tip 1: How to find out what node.js packages you can use?
The different node.js packages that can be used within Testim are the ones found in https://www.npmjs.com/. This is the official website that has references to all the open source node.js packages. Say for example, you are searching for a package related to pdf documents; just search for “pdf” and you will get a list of all the node.js packages available for pdf.
Tip 2: What are the available CLI action steps within Testim?
Below are the available CLI action steps within Testim-
- Add CLI action
- Add CLI validation
- Add CLI wait for
- Validate download
- Wait for download
Tip 3: How to add node.js packages to Testim?
To add node.js packages to Testim, follow the below steps
- Add one of the above mentioned CLI action steps
- In the Properties Panel, click on PARAMS-> PACKAGE
Tip 4: How to execute CLI action steps locally?
To execute node.js scripts via CLI action steps locally, you need to first set up the runtime environment using the below command. Ensure this command is executed from the command line before running a test with a CLI action step.
npm i -g @testim/testim-cli && testim –agent
Putting everything together
Lets see how all the tips work together to execute node.js scripts. Say you want to validate the content of a downloaded document such as a PDF file. The steps to do this would be-
- Ensure CLI Action feature is enabled (Contact our CSM or customer support for this)
- Add the “Validate Download” action
- Add the necessary node.js package for the pdf content validation. In this case, we are adding the latest version of the package pdf-parse
- Then, add the necessary code to do the content validation
Here is a sample test to show how to do PDF content validation – PDF Validation
For more CLI action examples, check out the last section of this doc – CLI Action