Quantity is getting appended instead of getting added in POST API Tag - httprequest

Below is my Robot Framework code for the POST API:
Create Session Update_inventory_details
${Base_URL}
${body}= Create Dictionary distributionPointId=7 menuItemId=1 quantity=1 transactionDoneBy=11 transactionType=1 reasonId=11 barcode=null
${Headers}= Create Dictionary Content-Type=application/json Authorization=bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InByaXRpc3dhaW4iLCJpYXQiOjE1Njc1MTQ2NDd9.o3qTPbj2KH6AgHpIf1BLV5nOlGL-fR83wSGAYyuWsBQ
${Response}= Post Request Update_inventory_details reportmenuiteminventorychange data=${body} headers=${Headers}
Log Many ${Response.status_code}
Log Many ${Response.content}
${actual_response}= Convert To String ${Response.status_code}
Should Be Equal ${actual_response} 200
On hitting the request via Robot Framework, the quantity tag value is getting appended to the actual quantity.
Example: inventory for item = 1000, adding quantity 1 via API-
Expected inventory = 1001;
Actual inventory = 10001
How do I send value in the quantity tag so that it added and not appended?
POSTMAN Request:
{
"distributionPointId":7,
"menuItemId":1,
"quantity":1,
"transactionDoneBy":11,
"transactionType":1,
"reasonId":11,
"barcode":""
}

Related

API Post request with RobotFramework - Empty Param

I have the following POST request to configure in RobotFramework,
trouble is that the devs set up the request as presented in the screenshot.
This is a file id which you get from a file manager and download it.
My question is since there isn't any params, key, value like FileID etc.
What would be your best bet to send that request successfully via RobotFramework?
[screenshot][1]
The code that I have tried is:
Create Session mysession url=${test_env} verify=true
&{body}= Create Dictionary id=d67b39a6-4ea9-497f-a653-5eb2da418d23
&{header}= Create Dictionary Cache-Control=no-cache
${response}= POST On Session mysession /download data=${body} headers=${headers1}
Status Should Be OK ${response} #Check Status as OK```
Response I receive is Bad Request or Unsupported media
[1]: https://i.stack.imgur.com/kGyHo.png

Getting 202 instead of 200 using Rest assured or Robot Framework

I have performed a GET request as follows:
TEST1 : Using Rest assured:
RestAssured.baseURI = my_BaseUri;
Response response = given().header("x-ibm-client-id", my_XibmClientId).auth().preemptive()
.oauth2(my_accessToken)
.accept(ContentType.JSON).when()
.get(my_BasePath + "/" + my_processId)
.then().log().all()
.extract().response();
TEST2 : Using Robot Framework:
${headers}= Create Dictionary x-ibm-client-id=${my_xIbmClientId} Authorization=Bearer ${my_AccessToken} Accept=application/json
${response}= Get Request mysession ${my_BasePath}/${my_processId} headers=${headers}
So the issue is: I always get a status 202 (accepted) instead of 200. However, it works properly with the POSTMAN (the response status is 200).
Thanks for your help.
Try using this:
${headers}= Create Dictionary x-ibm-client-id=${my_xIbmClientId}
Authorization=Bearer ${my_AccessToken} Content-Type=text/plain
${response}= Get Request mysession ${my_BasePath}/${my_processId}
headers=${headers} alias=API
I just added content-type= text/plain

How to use data in csv file row wise to be used per request via newman?

I have bunch of requests in my postman collection for example :-
Request 1
Request 2
...
Request N
For each of these requests , I want to pass a client id for which is unique per request. I have created a data file with those client ids. So the data in CSV file is as follows : -
Client Id
1
2
..
N
My requirement is to use Client ID 1 in Request 1 , Client ID 2 in Request 2 instead of iterating Client ID 1 though the entire collection.
So basically data in CSV file to be used row wise in all the requests.
Would really appreciate suggestions on how this can be achieved.
I tried using Runner but it doesn't fit my requirement
Maybe it would be easier not to use .csv file here, but Postman Environment Variables.
If you're having the number of ClientIDs matches the number of request, you can do something like this:
In the Pre-Request Script of first request you have to initiate an array of clientIDs:
const clientIdArr = [1,2,3,4,5,6,7,8,9,10];
pm.environment.set('clientIdArr', clientIdArr);
Then we will shift the first value of array of clientID in every subsequent Postman Collection request:
const currentArr = pm.environment.get('clientIdArr');
const currentValue = currentArr.shift();
pm.environment.set('clientIdArr', currentArr);
pm.environment.set('currentClientId', currentValue);
Then you can use {{currentClientId}} environment variable in your actual request and exectute the Postman Collection via Collection Runner.
For more details how Array.prototype.shift() works please refer to the following link.
If you have a large amount of requests in your Postman Collection you might consider having those scripts as Postman Global Functions.

KarateDSL Parsing a value from a response and adding to next scenario payload not working

New to Karate and I have read a load of the Karate tutorials and cannot get my head around what looks to be a trivial issue.
I have one post request that successfully lists all applications, from the response I get the ID of the first application and print it to console and it displays with no issue. However, when I come to use the applicationId in the payload for the next scenario (int he same feature file, the applicationId is not added to the payload.
Scenario: List all applications
Given path '/ListApplications'
And request {"request":{},"Session":'#(session)'}
When method POST
Then status 200
And def applicationId = response.Applications[0].Id
* print 'Hello ' + applicationId //i see the application id of 7203 here in the console log
Scenario: Get Application
Given path '/GetApplication'
And request {"request":{"ApplicationId":'#(applicationId)'},"Session":'#(session)'}
When method POST //post here just uses string applicationId instead of 7203
Then status 200
Any help greatly appreciated
You are using 2 Scenarios where you should have only one.
Please read this section of the docs: https://github.com/intuit/karate#script-structure
I think if you comment out this line it will work:
# Scenario: Get Application

karate | xml post method exeuction

I’m having issue with xml post request where post method is not executed. When I try to post same request body in post man it worked.My test is success with 200 but actual request is not executed.
Please let me know if I’m missing
To pass the request body,I’m calling through java object and payload is correctly constructed and printed.In execution test is success and doesn’t print response.But actually test is not executed.
Only headers are printed.
***************** create-user.feature*****************
Feature: create ims user for provided country
Requires country code,
Background:
# load secrets from json
* def createuser = Java.type('com.user.JavaTestData')
* def create = createuser.createUser("US")
Scenario: get service token
Given url imscreateuserurl
And request create
When method post
Then status 200
* print response
***************** create-user.feature*****************
Here is java class
public class JavaTestData {
private static final Logger logger = LoggerFactory.getLogger(JavaTestData.class);
public static String createUser(String countryCodeInput) {
logger.debug("create user for country code input", countryCodeInput);
Unless you post a full working example, no one can help you. Pretty clear that the value of create is null or empty.
Also I personally think you are wasting your time using Java. The whole point of Karate is to avoid using Java as far as possible.
Look at these examples for ideas: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature
Edit: also refer to the doc on type-conversion: https://github.com/intuit/karate#type-conversion
#Peter, here is my feature file
Feature: create ims user for provided country
Requires country code,
Background:
# load secrets from json
* def createuser = Java.type('com.adobe.imscreateuser.JavaTestData')
* def create = createuser.createUser("US")
Scenario: get service token
Given url imscreateuserurl
And header Content-Type = 'application/xml; charset=utf-8'
And request create
When method post
Then status 200
* print response
I have performed print for create and showing complete payload.At when method post -> statement its going as null or empty...
Not sure where it is missing