End-to-end API testing flows can involve multiple input sources, such as HTML, Databases, Telnet/SSH, Mobile, Shell commands, Data files, other RESTful APIs and more. TestProject‘s test automation platform allows not only testing your APIs manually, but also to complete end-to-end API based test automation flows, schedule and run them periodically, get execution reports and all of that without any third party tools and without a single line of code 🚀
This hands-on tutorial consists of step-by-step examples and real automated test flows, shared here for you to use and practice while automating your APIs. In this chapter (Chapter #4), we will walk through API test automation flows with combination of Shell Commands and Local Files. You can access the tests mentioned in the examples below by using the following shared test links:
- CMD Shell Commands and Restful API Test Example
- SSH Connection and Restful API Test Example
- CSV Operations and Restful API Test Example
- File Operations and Restful API Test Example
Table of Contents – Automating End to End API Testing Flows
- Overview – Automating End to End API Testing Flows
- Chapter 1 – Basic API Test Automation
- Chapter 2 – API Test Automation Flows Combined with Mobile Functional Test
- Chapter 3 – API Test Automation Flows Combined with Database Flows
- You’re here → Chapter 4 – API Test Automation with Combination of Shell Commands and Local Files
- Chapter 5 – Advanced API Test Automation and Validation Flows
- Chapter 6 – Scheduling API Automation Flows and CI/CD Execution
CMD Shell Commands and RESTful API Test Example
You can mix in CMD shell commands for the operating system you’re using inside your tests as well, these can be all-purpose commands such as creating files, running scripts or anything else you might need.
The following example will perform an API request and search for the city extracted with JsonPath on Google:
Afterward, we will use a CMD command to create a text file on the Desktop, extract text from a paragraph on the page and again, write it to the same file using a CMD command.
The file has been created, and the text stored in the ‘text’ parameter has been written to the file:
While performing your tests, you can also connect via SSH to remote machines and send commands similarly to the previous examples showcasing CMD commands.
You’ll need to install the SSH Commands Addon:
The following example will perform an API request, and then use an SSH command to write the results extracted via JsonPath in a file on a remote Linux machine.
After performing the API request, and saving the result into a parameter:
A connection can be established to the remote machine, by providing an IP, port, the machine’s username, the machine’s password and afterward the command that we would like to execute:
After running the step, the file will be created with the value on the remote machine:
Using the CSV Operations Addon, you can create and update existing local CSV files as part of your test flow.
The following example will perform an HTTP Get request and extract a value using JsonPath from the response.
Afterward, the next step in the test: ‘Update CSV file’ will update the specified CSV file with the extracted value:
After running the step, the file will include the updated value:
The following example will use the File Operations Addon to write the results of an API request to a local text file.
The inputs used in the action are:
1. The path to the local file where the content will be saved.
2. The contents that are going to be written in the file, currently stored in a test parameter.
3. A boolean value used to decide whether to create the file in case it does not exist in the specified location (currently it is set to ‘true’).
After running the step, the results will be in the file: