Skip to content

kannappansomasundaram1/ApiTesting

Repository files navigation

ApiTesting

A few API Testing tools were explored and findings were recorded here.

Table of content

  1. Postman + Newman CLI
  2. Http Files
  3. Playwright .net
  4. .net HttpClient
  5. Commandline

Postman Collection with Newman CLI

Examples available here

Export

Export the Collection from Postman in v2.1 Exported format is not easy to maintain.

Running the tests

Steps to run the tests,

  1. Install newman CLI
    npm install -g newman
  2. run the test using httpyac with the below command
    newman run .\PostmanTests\todos.postman_collection.json

ExecutionResult

Http Files

Files with .http extensions that allows to send http requests It supports,

  • running scripts to set variables
  • Asserting the response status code, fields etc

Running tests from IDE/Code Editor

Command line Options

Example using httpyac

Examples available here

There are three tests,

  1. Fetch all Todos from API
    • Asserts on the response status code,
    • Sets the variable todoId to be used in the next tests
  2. Fetch Todo Items based on Id saved from previous test
    • Asserts on the response status code
  3. Fetch Todo Items based with invalid url to get 404 to simulate failure

Setting global variable

> {%
  // Set todoId as global variable to use it in subsequent request
  client.global.set("todoId", response.body[2].id);
%}

Assertion

//Assert status code
  client.test('status code 200', () => {
    client.assert(response.status === 200, "Response status is not 200");
  });

Running the tests using httpyac CLI

I tried to run these tests with httpyac CLI. Steps to run the tests,

  1. Install Httpyac CLI
    npm install -g httpyac 
  2. run the test using httpyac with the below command
    httpyac Tests.http -all -o response -v

Test Result

Playwright tests

https://playwright.dev/dotnet/docs/api-testing

Example available here

.Net HttpClient

API Requests can be made using .Net Http Client and results can be verified
Example available here

Commandline Options

1. cURL

This is my default CLI tool to send API requests,

curl --location 'https://jsonplaceholder.typicode.com/todos/1'

Parse data using jq

curl --location 'https://jsonplaceholder.typicode.com/todos' | jq '.[].title'

2. httpie

https://httpie.io/

choco install httpie

Example

 http https://jsonplaceholder.typicode.com/todos/1
http POST pie.dev/post < files/data.json

3. Bombardier

This is my favourite tool to fire a quick performace tests on an API.

https://github.com/codesenberg/bombardier

bombardier -c 2 -n 10 https://jsonplaceholder.typicode.com/todos/1

Output

BombardierOutput

About

Explore different Tools to test APIs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages