Rest Assured Java : How to obtain id in the response not in json format - testing

I need to obtain the response of an endpoint that returns a number but not in json format, only a number returns. When I try to do response.prettyprint() I didnt see nothing in the console. Is there any way to obtain that number in the response? Thanks!

To print that information, just use:
Response res = ...
res.print();
To get Infor, save Response as String then convert type to int
String res = ...asString();
int number = Integer.valueOf(res);

Related

Karate / Post Request : Unable to pass random generator variable in json payload

I am trying to create Karate feature file for API Testing.
It is a post request and we have to pass random number for 1 field i.e. order in request payload every time.
Now, I am trying to use this function in the same feature file to pass that random generated value in json payload before sending post request.
Could someone please have a look at my feature file and help.
Thanks
Also, Is there a way if i want to pass this same random value for a json payload created as a separate request.json payload file
Your requestPayload is within double quotes, so it became a string.
Here's an example that should get you going. Just paste it into a new Scenario and run it and see what happens.
* def temp1 = 'bar'
* url 'https://httpbin.org/anything'
* def payload = { foo: '#(temp1)' }
* request payload
* method post
And please read the documentation and examples, it will save a you a lot of time.

Print keyword displays blank when response includes long encoded chars

I am testing an endpoint that takes a json body as request and return a json object with one field with encoded value for a pdf generation. I get 201 status code, but I could not get to print the response. It looks blank in console.
Sample Request Paylaod might be;
{'name': 'firstName',
'lname': lastname }
and response looks like below;
{ 'getPDF': 'JBKJGHUKSxjsnckdskcnejcnd/vdsv+VFDVfsd..........'}
And I just print the response as below;
* status 201
* print response
but it does not print anything. Is there a way to print the encoded value in the response?
Thanks.
It sounds to me that the response is actually empty. Anyway if it is bytes, you can try convert to a string:
* string response = responseBytes
If that doesn't work - who knows, Karate may have a bug :) So please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

How to convert to a web response from a record/data-frame

I have an application where I am returning a data frame/record. I want to return a web response, how should I convert it to. Tried dumping in son but didn't work using web.jsonresponse.
Here is the return type that I want to convert into web.response so that I can use the status field of response.
[<Record id='CORN' description='primary subject of interest'>]

How to pas ISO 8601 formatted date value in GET Request

I am working on lob.com letters API. Using Postman application to test the API, facing the following error:
Postman Application to test Lob's API
The parameter "date_created" want date value in ISO 8601. I am passing the value in specified format but api returns the response having error: "date_created must be an object".
Need help!
In pre request script compute current date and set it to environment variable then you can pass it in your request body. A bit of code will look like this:
Pre Request
var date = new Date().toISOString();
postman.setEnvironmentVariable("date",date);
Request Body
// Other attribs....
"date_created" : "{{date}}"

How to get web api request data (Get,Post,Put and Delete) from the raw request itself not receiving it in a method parameters

I am using WorkContext that contains information about the current request such as logged-in user, current culture and so on;
My question is i want to Interrogates HttpContext.Current to get data from request;(Method Body; i already know how to get it from query string) i mean i want to get Jason Data that is passed when the user make the request in case of Get,Post,Put and Delete requests; note i want to get data from raw url HttpContext.Current.Request not receive data in a method paraemeter as i want to get generic data that is common on all methods
I think the property you want (assuming I understood your question) is HttpContext.Current.Request.RequestType. If you wanted Json you could do:
var rType = new { Method = HttpContext.Current.Request.RequestType };
var thing = JsonConvert.SerializeObject(rType);