Karate : Passing variable from one feature file to another as a query parameter [duplicate] - karate

This question already has answers here:
Can we parameterize the request file name to the Read method in Karate?
(2 answers)
Closed 1 year ago.
I'm trying to execute a feature file and need which takes a query parameter from another feature.
Here is the feature files :
1. This file call two feature files. First feature file add a record in the database and returns json response. I have to use a property from the response and have to pass to another feature. Please find below for the features files.
Feature:
Background:
Scenario:
Given call read('test_add.feature')
And def query1 = response.name
Given call read('test_get.feature') {'**query**' : #query1}
feature name - test_get.feature
Feature: Add a new Nat bundle device
Background:
url baseUrlWithContext
def headers = { 'Content-Type': 'application/json' }
Scenario: Addition
Given headers headers
And path '/test'
And params query
When method get
Then status 200
Error :
com.intuit.karate.exception.KarateException:
cannot convert to map: query

Instead of And params query
Try this:
And param query = query

Related

How do I pass apikey as authorization in a POST/GET request in Karate Framework feature file [duplicate]

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

Creating a re-usable feature file which can accept different json payloads [duplicate]

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

Validating API response in Karate framework [duplicate]

This question already has answers here:
Can we parameterize the request file name to the Read method in Karate?
(2 answers)
Closed 1 year ago.
I want help for validating API response using karate framework.
I have API’s which are “Independent” on each other.
I have POST method along with request parameters. when I hit that particular API got the response with different parameters (no single match from request parameter and response parameter).
Now I want to validate response parameter value.
example : request: “method” post
school name: “abcd”
register date : “1:10:2010″
Response:
Principle name : ” pqrs”
Principle Email id “pqrs#gmail.com
now I want to validate that “principle name ” should not be null
I have implemented like this but it it doesn’t work
Feature: School info
Background:
* url baseUrl
Scenario: check Principles info
Given path ‘School info’
And request {school name: “abcd” ,register date : “1:10:2010”}
When method post
Then status 200
And match response.response contains {“type”: “Success”,”code”:20000}
And match response.principle list[*] { “Principle name”: “#notnull”}
whenever I run this file it always passes the API wvwnt if the Principle name filed is null.
It just checks the success message (And match response.response contains {“type”: “Success”, ”code”:20000}) and pass the API
your code for validating principlelist doesn't have proper assertions.
match each will be more convenient for validating json array with a schema
* match each response.principlelist contains {"Principal name" : "#notnull"}

karate api : Required request part 'file' is not present [duplicate]

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.
When i am tring to upload a image using karate framework i am getting exception as
{
"message":"Required request part 'file' is not present",
"code":500,
"className":"org.springframework.web.multipart.support.MissingServletRequestPartException"
}
Karate code
Scenario: Adding image
Given path Endpoints.upload_file
And multipart file myFile = { read: 'karate-logo.jpg', filename: karate-logo.jpg', contentType: 'image/jpg' }
And multipart field message = 'image test'
When method post
API works fine when i try to hit using postman.
Just need to send file in body section with form data key as 'file' and value as the image to upload.
The "key" here myFile is the name of the uploaded field. Looks like your server is expecting file. Please rename myFile to file and it should work.

Is Karate able to validate Excel file for a download endpoint? [duplicate]

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