Many at times we need to use different content types , headers , parameters while working with different API testing.
Today i have figured out a way how to send a different content type as x-www-form-urlencoded for a POST request.
For one my project we have to generate access token using content type as x-www-form-urlencoded and I found it difficult to send it from rest assured or Karate code. However it was easy to send the same request using POSTMAN.
Finally after a lot of trial and error and search over google I found a solution.
USE CASE:
1- Make a POST request
2- Set contet-type as x-www-form-urlencoded in Body (Hence there will be no body content for this content type, only it will have related form parameters)
3- Set 3 parameters for the above content-type
– grant_type : password
– username: abcd
– password: abcd

Now I have done the above request using KARATE API as below.
Feature: To test Authentication API using x-www-form-urlencoded
Scenario: Generate access token
Given url 'https://login-qa.mywebsite.com/api/v1/token'
And header Content-Type = 'application/x-www-form-urlencoded'
And form field username = 'user_ppr_test01@yopmail.com'
And form field password = 'Test@12345'
And form field grant_type = 'password'
And request {}
When method post
Then status 200
Output:
1 < 200
{"access_token":"5bb73fc5-6e69-43b6-931d-eb80c87a2cc9","token_type":"bearer","expires_in":1799}
Very helpfull…
Thanks 🙂
LikeLiked by 1 person
Excellent!!
LikeLike
what if we are fetching value in one call and then assigning it to another form field, how can we do this?
LikeLiked by 1 person
Trying to understand better, let me know if I understood it right,
1- Make a GET/POST call, fetch some value from its response, lets say “email”
2- Use this email value in another POST call as form param?
LikeLike
what if we are fetching value in one variable and then assigning it to another form field, how can we do this?
LikeLike