Karate API: File upload Possible in lower version (0.9.5) but unable proces the same in another version(1.3.0.RC1) - api

Excecuted the below statement in 0.9.5 version and get the proper response.
URL : ""
header Content-Tyep= "multipart/formdata"
multipart field metadata = {"key":"FILE_NAME",
"vale":"test" }
multipart field metadata = {"key":"FILE_EXTENSION",
"vale":"jpg" }
........
method post
status 200
get proper response
but in 1.3.0.RC1 getting below error
required list parameter 'metadata ' is not present
please suggest some ideas
is there any alternative way for above 0.9.5 versions

Related

Karate api testing- assertion getting failed when version 1.1.0 and 1.2.0.RC1 is used . Same assertion is passing when 1.0.1 and 1.0.0 version is uesd

Feature file with scenario
Feature: reqres api test cases
Scenario: list all users get request
Given url "https://reqres.in/api"
And path "/users?page=2"
When method get
Then print response
And match response.data[0] == {"last_name": "Lawson","id": "#ignore","avatar": "#ignore","first_name": "Michael","email": "michael.lawson#reqres.in"}
Error message in ide
match failed: EQUALS
$ | not equal | actual does not contain key - 'last_name' (MAP:MAP)
{"id":1,"name":"cerulean","year":2000,"color":"#98B2D1","pantone_value":"15-4020"}
{"id":"#ignore","last_name":"Lawson","avatar":"#ignore","first_name":"Michael","email":"michael.lawson#reqres.in"}
You are not using Karate correctly. Note the usage of param below:
Given url "https://reqres.in/api"
And path "/users"
And param page = 2
When method get

ArrayIndexOutOfBoundsException use karate 0.8.0 [duplicate]

I'm trying to upload images on specific slack channel using Karate but no luck, I tried multiple times with different steps but still have 200 response and the image is not displayed in the channel.
Tried to post text content and successfully found the text on the channel.
Bellow are 2 of my tries following the Karate documentation:
#post
Feature: Post images
Background:
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}
Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200
OR
Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200
Am I missing something? Tried the same examples found in Karate demo GitHub repository of uploading pdf and jpg but no luck.
Note: worked using Slack API UI.
You seem to be mixing up things, there is no need for a request body when you are using multipart. Your headers / params look off. Also based on the doc here, the name of the file-upload field is file. Try this:
Scenario: upload image
Given url 'https://slack.com/api/files.upload'
And multipart file file = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
When method post
Then status 200
If this doesn't work, take the help of someone who can understand how to interpret the Slack API doc. Or get a Postman test working, then you'll easily figure out what you missed.

Unable to upload multipart file in karate, Required request part '' not present

ActualAPIRequest OutputFromKarate
Trying to upload a json file for an api using karate. Since api takes multipart input i am passing multipart configurations in karate.
But Required request part 'inputData' not present error is coming. Is there any solution for this please?
I have attached actual input and result from karate screenshot for reference
Just make sure that the data type of inputData and maybe swaggerFile is JSON. Looks like you are sending a string.
Please refer to this section of the doc: https://github.com/intuit/karate#type-conversion
If the server does not like the charset being sent for each multipart, try * configure charset = null

Karate API: JSON parsing error shown instead of wrong HTTP code returned

Given have the following list of steps
Given path 'verify'
And header x-api-key = apiKey
And header tenant-id = tenantId
And request a_json_object_with_invalid_user_id_to_verify
When method put
Then status 404
When the endpoint returned HTTP 200 (which is a bug that i need to fix) but with an invalid json response such as
{
"score" :
}
This exception is thrown
com.jayway.jsonpath.InvalidJsonException: net.minidev.json.parser.ParseException: Unexpected character (}) at position 15.
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.parse(JsonSmartJsonProvider.java:64)
at com.jayway.jsonpath.internal.JsonContext.parse(JsonContext.java:82)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
at com.intuit.karate.JsonUtils.toJsonDoc(JsonUtils.java:84)
at com.intuit.karate.StepDefs.method(StepDefs.java:344)
I expect to see the test failed because of wrong status code 200 received of the expected 404. I would like to know if throwing this exception is correct in karate?
Thanks.
I apologize for mis-reading your question.
There is indeed a bug in Karate when handling malformed JSON responses.
We have opened an issue, you should be able to get a patch version very soon: https://github.com/intuit/karate/issues/259

Extract report results with CloudConnect

I would like to extract raw report results within the CloudConnect process.
So far I have managed to get response from the raw report API end point - https://secure.gooddata.com/gdc/app/projects/{project_id}/execute/raw/
This response contains URI to the file and if I put that URI to browser, file is uploaded.
I have tried passing this URI to the following readers without success:
CSV Reader produces the following error:
------------------- Error details ------------------
Component [CSV Reader:CSV_READER] finished with status ERROR.
Parsing error: Unexpected end of file in record 1, field 1 ("date"),
metadata "outOfStock";
value: Raw record data is not available, please turn on verbose mode.
File Download - I don't know how to pass the URI through the port to "URL to Downlaod" parameter.
HTTP Connector again I don't see how to pass URI from the port.
What is the way to do this?
EDIT
If I use the HTTP Connector as suggested by #Filip, I get the following error:
Error details:
Component [HTTP connector:HTTP_CONNECTOR] finished with status ERROR. hostname in
certificate didn't match: xxx.com != secure.gooddata.com OR secure.gooddata.com
I have tried setting header to X-GDC-CHECK-DOMAIN: false with no effect.
The HTTP connector is the right component to go with. Leave the URL property empty and use the component’s property called “Input mapping”, where in the graphic editor you can assign the input edge field to the URL field.
Solution from GoodData support:
HTTP connector can be also used, but it is very complex, because
logging in to GoodData has to be created. REST connector has it built
in.
If you want to run the example graph, you have to be logged in in
CloudConnect with a user who has access to the project from where you
would like to export the report. You also have to change URL to
the one of white-labeled account in both REST connector components and change project
and report definition in the first REST connector.
So the graph that works looks like this:
Here are the main fields that you will need to set for each element:
Get Results URI - set params for POST request:
Request URL = https://secure.gooddata.com/gdc/app/projects/${GDC_PROJECT_ID}/execute/raw/
Request Body =
{
"report_req": {
"reportDefinition": "gdc/md/${GDC_PROJECT_ID}/obj/${OBJECT_ID}"
}
}
Get URI from Response - just map uri value to corresponding field:
<Mapping cloverField="uri" xpath="uri"/>
Load Results - make sure it is connected to metadata with two fields, one for response with data, other to pass through the uri.
Load Results - you will need to exclude uri field to process the data:
Exclude Fields = uri