Retry until with dynamic path or params [duplicate] - karate

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

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.

I am facing issue in jmeter

When I record and run the test in login transaction one request is failed.i check that request I found in post data session id keep on chenging.i did correlation for that Id .after I want to replace the variable name insted of that Id.but it not replace. Because that Id is not there any subsequent requests and any parameter value undre the requests.how I need to handle that Id how to replace it... please help me for the above issue
Note: I search that ID in view results tree it showing that Id passing in 3subsequent requests
Make sure that you really "did correlation for that Id", i.e.
Double check that the variable has the anticipated value using Debug Sampler and View Results Tree listener combination
Make sure that the placement of the Post-Processor performing the correlation is correct as according to JMeter Scoping Rules the Post-Processor is applied to:
One Samples only if it's placed as a child of this sampler
All the Samplers which reside at the same level (or lower) with the Post-Processor
so it might be the case you're overwriting the variable with the empty value somewhere else.

API additional id,

I'm trying to get data from my limesurvey and wonder why in API request I need to pass id: 1 as the third body parameter.
{method:'get_session_key',params:['myusername','mypassword'],id:1}
If I omit id or pass id:0, I will get the response data with an empty string. I can put any positive and negative integers there and I don't know exactly why it is required.
I'm following instructions on RemoteControl 2 API
That's the request id.
On the jsonRPCClient (component outside of LS) code it is fixed to 1.
I think it is part of a standard to use notifications, which are not used on LS API.
So, just fix it to 1 :)

Karate : Is it feasible to iterate Url to support pagination

I have a rest endpoint with pagination, I want to verify expected parameter exists by traversing through all pages. One option I could think of is to have an array defined with page offset intervals like {0,25,50....}
Welcoming better approaches. Is it feasible to break the loop when my expected condition is met?
ex: Given url 'http://myhost.com/v1/cats/'+'#(offset)'
And request {name : 'Billie'}
When method post
Then status 201
Note: have not tested the above code, looking for better approach.
You should be able to figure this out with conditional logic: https://github.com/intuit/karate#conditional-logic
There should be some part of your response that tells you whether there is a "next" page or not. There are ways you can "loop" manually, refer this part of the docs: https://github.com/intuit/karate#polling

Linkedin REST API - How to return more job bookmarks / records each call

I'm trying to get all my job bookmarks (30+) via Linkedin Rest API but it seems that every call only returns the same exact & only 10 records max.
GET https://api.linkedin.com/v1/people/~/job-bookmarks
then I found the end https://developer.linkedin.com/docs/rest-api
It seems that I can pass the parameter - count: The maximum number of items you want included in the result set. So I thought maybe I can just add that at the end of the GET url...
New query GET https://api.linkedin.com/v1/people/~/job-bookmarks&count=30
then I got an error - 400 Bad Request
Does someone know how to solve this problem? Many thanks!
You need to start the query string with a '?' instead of '&'.
https://api.linkedin.com/v1/people/~/job-bookmarks?count=30
You use '&' to separate query parameters. For example if you wanted to page through all the job book marks you could use the 'start' parameter to do offset paging. So the path to get the next page if you have more than 30 bookmarks would look like this.
https://api.linkedin.com/v1/people/~/job-bookmarks?count=30&start=31