logo logo

API Test Automation with Combination of Shell Commands and Local Files

Shell Commands

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:

  1. CMD Shell Commands and Restful API Test Example
  2. SSH Connection and Restful API Test Example
  3. CSV Operations and Restful API Test Example
  4. File Operations and Restful API Test Example

Table of Contents – Automating End to End API Testing Flows

  1. OverviewAutomating End to End API Testing Flows
  2. Chapter 1 – Basic API Test Automation
  3. Chapter 2 – API Test Automation Flows Combined with Mobile Functional Test
  4. Chapter 3 – API Test Automation Flows Combined with Database Flows
  5. You’re here → Chapter 4 – API Test Automation with Combination of Shell Commands and Local Files
  6. Chapter 5 – Advanced API Test Automation and Validation Flows
  7. 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:

CMD Shell Commands and RESTful API Test Example

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.

CMD Shell Commands and RESTful API Test Example

The file has been created, and the text stored in the ‘text’ parameter has been written to the file:

CMD Shell Commands and RESTful API Test Example

SSH Connection and RESTful API Test Example

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:

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:

SSH Connection and RESTful API Test Example

SSH Connection and RESTful API Test Example

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:

SSH Connection and RESTful API Test Example

SSH Connection and RESTful API Test Example

After running the step, the file will be created with the value on the remote machine:

SSH Connection and RESTful API Test Example

CSV Operations and Restful API Test Example

Using the CSV Operations Addon, you can create and update existing local CSV files as part of your test flow.

CSV Operations

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:

CSV Operations and Restful API Test Example

After running the step, the file will include the updated value:

CSV Operations and Restful API Test Example

File Operations and RESTful API Test Example

The following example will use the File Operations Addon to write the results of an API request to a local text file.

File Operations

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’).

File Operations and RESTful API Test Example

After running the step, the results will be in the file:

File Operations and RESTful API Test Example

💫 TAKE ME TO CHAPTER #5 💫

About the author

David Goichman

Automation has been a great passion of mine from day one. Software Engineer at TestProject.

Leave a Reply

FacebookLinkedInTwitterEmail