API Automation Testing

Hi Guys,

Today I thought of sharing the API Automation that I had recently implemented using C# & Rest Sharp [“Postman” is used for converting the Curl commands in “Swagger“!]

The challenges that I faced here are

  1. I need Oauth2 authentication for the app that I am currently automating [Banking Application]
  2. Then nothing, just kidding man.

So first question is how to GetToken?

It’s very easy (assuming that you already have the credentials with you / curl).

  1. Just paste the Curl Command in Postman
  2. In post man, click “Code”and copy the Rest Sharp code into clip board.
  3. capture
  4. You are ready to go. Paste it any where you want!!!

 

var client = new RestClient("https://testidentityservice.fasteningcode.co/connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "c9392696-b4b5-aadh-bose-4a9cb007a245");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "client_id=" + ClientId + "&" +
"client_secret=" + ClientSecret + "&" +
"grant_type=" + GrantType + "&" +
"username=" + Username + "&" +
"password=" + Password + "&" +
"scope=" + Scope,
ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

 
Notes

  • Postman is a Chrome App. This means that Postman can only run on the Chrome browser.

One thought on “API Automation Testing”

Leave a Reply

Your email address will not be published. Required fields are marked *