This question already has an answer here:
Karate: Is there a way of getting JSON object keys length from an Examples variable?
(1 answer)
Closed 1 year ago.
In Karate framework using Visual studio, I am making a REST call. I need to get the response size in KB or MB.
I tried these:
print response.size
Response: [jdk.dynalink.beans.SimpleDynamicMethod int java.util.HashMap.size()]
print response.length
Response: 6
This is the # of nodes of the response (items,hasMore,count,limit,offset,links)
print responseHeaders
Response: This gives me the response headers. It does not have response size
Can someone suggest a way to get the response size?
The responseBytes will contain the raw bytes and you can get the JavaScript length property like this:
* print 'size:', responseBytes.length
Note that I am using Karate version 1.X
Related
This question already has an answer here:
How to loop through karate response array and pass this in json path of another web service response
(1 answer)
Closed 1 year ago.
I need to call feature from another with passing array of jsons requests and call it several times for each json in array.
Example:
default payload.json:
{request.json}
arrayPayloads.json:
[{request.json},{request.json}]
When I calling another feature:
* def payload = read ('file: src/../arrayPayloads.json')
* def ex = call read ('..example.feature') payload
example.feature:
Background:
* def payload = karate.get('payload', read('file: src/../payload.json'))
Given path URL
And request karate.forEach(payload, )
When method post
You have some fundamental mistakes in your code. Please spend some time reading the docs and examples.
See this answer for example: https://stackoverflow.com/a/52019349/143475
Please don't have a space after read. It should be like this:
* def ex = call read('example.feature') payload
And this is completely wrong and won't work:
And request karate.forEach(payload, )
This doesn't make any sense at all:
* def payload = karate.get('payload', read('file: src/../payload.json'))
If you are still stuck, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
This question already has an answer here:
Passing JSON request starting with the character [ gives the error: invalid request format with GET operation [duplicate]
(1 answer)
Closed 2 years ago.
I'm attempting to send a simple POST request and struggling slightly.
Postman data request shown
--data-raw '""'
Given url TESTURL
And request '""'
When method post
Then status 200
A 500 response is returned every time, this works in postman. What am I missing?
Try adding a header
* header Content-Type = 'text/plain'
This question already has an answer here:
Is there a way to update the headers in one feature file and use the Auth token from Karate.config.js?
(1 answer)
Closed 1 year ago.
This is the first time I am trying my hands at Karate for my work. I have a feature file that is a GET request and uses an authorization method as an apikey but when I am passing an authorization as a header its giving me an error
"required (...)+ loop did not match anything at input 'Scenario:'"
Below is my feature file for reference
Feature: Get Profile
Background:
* url 'https://csXXX-XXXX.XXXXXXXXX.net'
* header Accept = 'application/json'
* header Authorization = 'apikey XXXX-XXXX-XXXX-XXXX'
Scenario: Profile GET on an id
Given path '/v1/Profile'
And param idProfile='XXXX'
When method get
Then status 200
Any help is appreciated.
Looks like you missed the Feature: at the top of the file.
I suggest you use the quickstart or ZIP release, so you get a ready to use test to try: https://github.com/intuit/karate#getting-started
This question already has an answer here:
How to compare 2 JSON objects that contains array using Karate tool and feature files
(1 answer)
Closed 1 year ago.
I want to create a re-usable feature which can be called by other feature files and that re-usable feature file should accept different json payloads
I want the analyticPayload to accept json file which is passed from createAnalytic.feature
1) createAnalytic.Feature -->
Given url xyz
And headers abc
And header Content-Type = 'multipart/form-data'
And multipart field analytic = analyticPayload
And multipart file file = templateJar
When method POST
Then status 200
2) createAnalytic.Feature -->
Scenario Outline:
* def analyticEntry= call read('classpath:tests/commonFeatures/createAnalytic.feature') {analyticPayload:<analyticPayload>}
Examples:
|analyticPayload|
|read('classpath:payloads/analyticCreation/createPowerAnalytic.json')|
Getting the error : :1:97 Missing close quote
com/ge/KraftTests/commonFeatures/createAnalytic.feature') {analyticPayload:powerAnalyticTemplate}
^ in at line number 1 at column number 97
that re-usable feature file should accept different json payloads
In my opinion, no it should not. Can you please read this answer carefully - and if you still want to go down this path, open a new question.
https://stackoverflow.com/a/54126724/143475
This question already has answers here:
How to get the downloaded xlsx file from the api endpoint in karate?
(2 answers)
Closed 1 year ago.
I am trying to confirm the file downloaded from an api. After reviewing the recommendation from How to test download api using karate, my scenario was written like below:
Scenario: GET /project - Export project listing
Given params { someparam: 'paramvalue' }
When method GET
Then status 200
And match header Content-Disposition == 'attachment;filename="someFile.xlsx"'
And match header Content-Type == 'application/vnd.ms-excel'
And match response == read('data/exported.xlsx')
The first 2 matches pass. However, the last match (comparing the actual file) fails with a binary printout of both files and "reason: not equal".
The file "exported.xlsx" in the comparison was the output of the exact same request done via Postman, so they should match.
Is read() able to handle excel and csv files? Any help would be appreciated.
As far as I know this should have worked. read('data/exported.xlsx') will return a stream of bytes.
If this is indeed a bug you will do a great service to the community if you follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue