1

I want to run my perticular scenario or feature file more than one time.

Let's say if user enter 5 then i want my url to be hit 5 times.

is it possible in karate? Any help would be appreciated

Yash
  • 121
  • 7

1 Answers1

1

Yes, read the docs: https://github.com/intuit/karate#loops

But also see example below using dynamic scenario outlines:

EDIT: using a Background will not work in Karate 1.3.0 onwards, please refer to this example: https://stackoverflow.com/a/75155712/143475

Background:
* def fun = function(i){ return { name: 'User ' + (i + 1) } }
* def data = karate.repeat(5, fun)

Scenario Outline:
* url 'http://httpbin.org/anything'
* request __row
* method post

Examples:
| data |

So run this, see how it works and study how it works as well.

Note that data driven features is an alternate approach where you can call a second feature file in a loop. So for example after using karate.repeat() 5 times like in the above Background, you use data as the argument to a second feature file that hits your url.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Hi Peter, I have tried running above example but getting below error variable 'data' is not defined. Seems like 'data' variable reference in Examples throwing error. Complete error info - * src/test/java/features/sample.feature[1:13] dynamic expression evaluation failed: data 0 js failed: >>>> 01: data <<<< org.graalvm.polyglot.PolyglotException: ReferenceError: "data" is not defined - .:program(Unnamed:1) – sanjay pujari Jan 20 '23 at 06:22
  • 1
    @sanjaypujari see my edit: https://stackoverflow.com/a/75155712/143475 – Peter Thomas Jan 20 '23 at 07:02
  • 1
    Thank you! Peter. It worked with the above changes you mentioned in edit. – sanjay pujari Jan 20 '23 at 07:36