Reputation: 4859
I want to have request a login URL 10 times. I did it this way:
Background:
* def loginAttempt =
"""
function(times){
for(i=0;i<times;i++){
karate.log('Run test round: '+(i+1));
karate.call('classpath:init/login.feature');
}
java.lang.Thread.sleep(1*1000);
}
"""
Scenario: Correct
* call loginAttempt 10
And this is the login.feature:
Feature: register a user
Scenario: call register for a user
Given url urlBase + loginUrl
And request
"""
{
"username": #(username),
"password": #(password)
}
"""
When method post
How to directly put the code in login.feature in the loop?
Upvotes: 1
Views: 2138
Reputation: 58098
The answer is you cannot. The only way you can re-use a set of feature steps in Karate is to move it into a separate feature file. I don't understand why you see this as an issue. This is actually good, because you can re-use the login from other tests.
If you really really want to have everything in one feature, write what you want to do in Java and then you can call it in a loop from a single feature file.
Upvotes: 1