Request mandatory for POST method call in Karate - karate

Today I came across a scenario where there was a POST method call but that does not require a request data and query parameters are sufficient. But in Karate framework it is mandatory to give request data when it is POST method. So I had to provide request as 'null' explicitly. Is there any way in Karate that if there is no request data then you can skip providing request data as 'null'.

This is what I usually do if there's no request body :
Given path '/path/to//action'
And request ''
When method post
Then status 200
(Haven't found a way to skip the request step)

I tried this way:
Given url 'url'
And params param_value
And request '{}'
When method post
Then status 200
Its same as mentioned above just I gave empty request body

Related

How to get the response body of JSON format when using Jenkins rest api to create job?

The .../api/json seems only working for query info with GET method. When I request /createItem?name=xxx or /createItem/api/json?name=xxx with POST method, it always return the response body of HTML。
This is very inconvenient to get error information,for example, when the job already exists,it return like this

How to pass multiple json records using data driven approach in Karate DSL?

We have gone through the Karate documentation where we can compare the exact JSON object as a response (which contains multiple data records) but how can we pass and read the JSON in a single scenario?
Below is my sample.JSON and I want to read this in the request payload.
[{"name":"John","salary":"10000","age":"25"},
{"name":"Maria","salary":"20000","age":"27"}]
I have tried the JSON structure in the above format, however, I am getting below exception. Kindly help me in this.
status code was: 400, expected: 200, response time: 4315
Kindly suggest how to read and pass it in request payload of single scenario.
Thank you.
Status code 400 means you have made some other mistake with the request. Karate is working fine, it is just an HTTP client, maybe the request was not in the "shape" the server was expecting. Talk to the server-side team if you can or check the documentation of the API.
Here is a simple example that works, paste it and try:
* def body = [{"name":"John","salary":"10000","age":"25"}, {"name":"Maria","salary":"20000","age":"27"}]
* url 'https://httpbin.org/post'
* request body
* method post
* status 200
EDIT: for looping, please read the documentation.
The below example is just one way of doing it - please identify what best you are comfortable with: https://github.com/intuit/karate#data-driven-tests
Feature:
Background:
* def data = [{"name":"John","salary":"10000","age":"25"}, {"name":"Maria","salary":"20000","age":"27"}]
Scenario Outline:
* url 'https://httpbin.org/post'
* request __row
* method post
* status 200
Examples:
| data |

Variable Path Param for GET request in Jmeter

I'm testing a GET request using Jmeter, this request has path parameter:
rest/V1/autobusca/marketplace/product/:productSku
I'm trying to send the parameter in two different locations
Send Parameters With the Request
And I insert a "User Parameters" as productSku and the value.
I noticed the code response is 200, but the body response is "[]", but when I send it using Postman the response body has a lot of information.
If I change the path in the request like this:
rest/V1/autobusca/marketplace/product/${productSku}
I noticed the code response is 404. Can you help me?
Use "//" instead of "/".
Correct URL will be : rest/V1/autobusca/marketplace/product//${productSku}

Karate API : How to hit an endpoint url with post method which does not have request body

I am getting below error when I am trying hit a endpoint url with post method which does not have a body. In postman I am able to hit endpoint url with post method without body. I tried all steps by referring the Karate API docs.
**Error** : com.intuit.karate.exception.KarateException: TestScenarios.feature:56 -
request body is required for a POST, please use the 'request' keyword
testurl is :
**test-api.test.com/test-com/api/check/initiate?
lang=en&cntCode=us&id=8d1b9355**
Attempt 1:
Given url 'test-api.test.com/test-com/api/check/initiate?lang=en&cntCode=us&id=8d1b9355'
When method post
Then status 200
* print response
Attempt 2:
Given url testurl
And param lang= en
And param cCode = us
And param id= '8d1b9355'
When method post
* print 'Response'+response
Attempt 3:
Given url testurl
And form field lang= en
And form field cCode = us
When method post
Then status 200
Can someone help me to understand the issue and wrong in my approach.
Two possible options depending on your server:
* request {}
Or as per the docs:
* request ''

How to pass regular expression extracted value in json format for PUT call in jmeter?

I am testing RESTapi with (json format) using (HTTP Request sampler) in jmeter. I am facing problems with the PUT calls for update operation.
The PUT call with parameters don't work at all using (HTTP Request sampler), so now i am using the post body to pass the Json.
How can i pass the extracted values from the previous response to next PUT request in thread group? Passing the 'Regex veritable' to PUT call in Post body don't work, it doesn't take ${value} in Post body.
How do i carry out UPDATE operations using (HTTP Request sampler) in Jmeter?
Check that your regexp extractor really worked using a debug sampler to show extracted value.
Check your regexp extractor is scoped correctly.
See this configuration:
A Variable:
Its use with a PUT request:
The sampler result: