Karate : can dynamic-csv.feature work for Get Request, how to pass dynamic path parameters from CSV? [duplicate] - karate

This question already has an answer here:
How do I invoke my JS Function for a particular column in a csv file in the Karate Framework?
(1 answer)
Closed 1 year ago.
Trying to pass dynamic path parameters from CSV for a GET method.
Referring to Karate: how to pass dynamic path parameters?
we are trying to pass dynamic parameter in path from a CSV file, but it doesn't work well when method is GET, although for POST we don't have an issue using CSV.
here elaborating with help of a open API
Feature: Get users details based on valid and invalid inputs from csv file
Background:
* url 'https://reqres.in'
Scenario Outline: Get single user based on id value - Valid & invalid
Given path '/api/users/<id>'
When method <method>
Then status <status>
* print response
##* match response.data.id contains <id>
Examples:
|id|status|method|Scenario|
|2|200|GET|Valid id as input|
|4|200|GET|Valid id as input|
|5|200|GET|Valid id as input|
|&|404|GET|Special character as Input|
| |404|GET|Empty space as Input|
|A|404|GET|Alphabet as input|
|999|404|GET|Invalid Number as input|
|-1|404|GET|Invalid Number as input|
This works well, but when I try to pass same data with following it doesn't work
|read('../../Data/users.csv')|
this is how this CSV looks
users data csv file

It is hard to say from the data given, and it doesn't work is not helpful. Maybe special characters cause problems. The best thing would be to follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
In general I discourage using a Scenario Outline for negative cases. Some guidance can be found here: https://stackoverflow.com/a/54126724/143475
To troubleshoot the CSV, you can try * print __row to see the values in each row.
This works for me:
Scenario Outline:
* url 'https://httpbin.org'
* path 'post'
* request __row
* method post
Examples:
| read('test.csv') |

Related

Jmeter :- ArrayList Handling in Parameters tab

Case: Select 100 records and mark them verified.
Steps:
Getting 25-100 records based on IDs via JSON extractor.
Posting verified on 25-100 records selected.
Actual Result: (Getting 500 Error)
Expected Result: (How it is working in application)
How can I handle the above case?
Your format is not correct, you need to send the data like:
The request body can be generated dynamically using JSR223 PreProcessor and some Groovy scripting, check out HTTPSamplerBase.addArgument() function for more details.

Values of a particular column of CSV file is not fetched properly in Json payload (Karate Framework)

I am working on specified scenario too.
My .csv file is as follows:
And test steps are:
Scenario Outline: Create new content value for movie: '<Movie>'
When json payload = {'attributes':[{'entity_attribute_id': 41,'value': '<Genre>'},{'entity_attribute_id': 42, 'value': '<Language>'},{'entity_attribute_id': 39,'value': '<Movie>'},{'entity_attribute_id': 101,'value': '2020-12-03'}],'entity_type_id': '10'}
Given url baseUrl + postContentValues
And request payload
When method post
Then status 200
And print response
And def contentId = response.id
Examples:
|read('RoughTable.csv') |
On test execution, "Movie" are not fetched while "Genre" & "Language" are obtained as expected from .csv file
Please guide me for solving this issue.
I think there may be an issue with CSV loading. Can you add an extra dummy column before Movie.
Either way, please submit a way to replicate, this will help us fix it: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Retry until with dynamic path or params [duplicate]

I have a use-case where I need to first call an API to get a list of ID's. From this response a random ID is chosen. Next I call a 2nd API which uses the random ID as a component in the path.
It's possible the 2nd API call can return an empty response, therefore I want to utilize retry until but use a different random ID in the path per retry iteration.
I've tried a couple of things:
First "in-lining" the JS function in the path to get a random ID:
Given path firstPart, myGetRandomId(idList), lastPart
And retry until response.length > 1
Second, tried putting the JS function in a Examples: as part of a Scenario Outline:
Given path firstPart, <ID>, lastPart
And retry until response.length > 1
Examples:
| ID |
| myGetRandomId(idList) |
The general issue I can't figure out is how to get the JS function to evaluate in either of this "in-line" kind of approaches.
And ideas/suggestions appreciated.
The way that the Karate retry until works is that it will re-play the request as-is and you can't modify it.
So you have to take a different approach. Use a JS loop. Look at this example in the demos:
https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/polling/polling.feature

How can we compare two XML API responses in karate framework without considering Date tag in it

If i am saving two responses with different data in a * def variable. Then how can i compare these two without considering date or few tags data in it.
It is a good practice to show with an example of what you have done and where you need help so it can be answered better.
You can set the values of such nodes to an empty string and then compare:
set cat /cat/name = ""
If you have an expected response XML as file, you can easily use the #ignore tag which is supplied by Karate.
For example:
< Date_time >#ignore< / Date_time >
When you compare the file on your disk with the actual response Karate will ignore the #ignore tags.
Hope this helps.

Karate Automation: Is there any way we can set the Scenario name dynamically from a json file [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 am using a JSON file which act as a test case document for my API testing. The JSON contain Test Case ID, Test case Description, Header and Request body details, which should be the driving factor of Automation
Currently i am looping a feature over this json file to set different header and body validations. However it will be helpful if i can set the Scenario name from JSON file while its iterating
Something like
serverpost.feature
Feature:re-usable feature to publish data
Scenario: TC_NAME # TC_NAME is avaliable in the JSON data passed to this feature. However, CURRENTLY ITS NOT TAKING THIS DATA FROM JSON FILE.
Given path TC_ID # TC ID is taken from JSON
Given url 'http://myappurl.com:8080/mytestapp/Servers/Data/uploadServer/'
And request { some: '#(BODY)' } # Request Body Details is taken from JSON
Please suggest
In my honest opinion, you are asking for a very un-necessary feature. Please refer to the demo examples, look for it in the documentation.
Specifically, look at this one: dynamic-params.feature. There are multiple ways to create / use a data table. Instead of trying to maintain 2 files - think of Karate as being both - your data table AND the test execution. There is no need to complicate things further.
If you really really want to re-use some JSON lying around, it is up to you but you won't be able to update the scenario name, sorry. What I suggest is just use the print statement to dump the name to the log and it will appear in the HTML report (refer to the doc). Note that when calling a feature in a loop using a JSON array, the call argument is ALREADY included the report, so you may not need to do anything.
Just an observation - your questions seem to be very basic, do you mind reading the doc and the examples a bit more thoroughly, thanks.