anonymous
anonymous

Reputation: 101

Passing multiple parameters using karate.call

I am trying to call an API in second feature file , passing arguments from first feature file . Say token and current page value which is returned from a first API response.These has to be passed as a param for second API

   * def activeDetails =
    """
      function(times){
        for(i=0;i<=times;i++){
          karate.log('Run test round: '+(i+1));
          karate.call('getActiveRouteDetails.feature', { token: token, currentPage: i });
        }
        java.lang.Thread.sleep(1*1000);
      }
    """
* call activeDetails totalPages

In my second feature , I am able to print the values passed , but unable to pass in params . Can you please help me

And print currentPage
And print token
And param pageNumber  = '#currentPage'
And param token = token

Upvotes: 1

Views: 8569

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58098

There is a subtle difference when you are in a JavaScript block. Please read this: https://github.com/intuit/karate#karate-expressions

Make this change:

var result = karate.call('examples/getDetails.feature', { token: token, currentPage, i });

And please don't have variable names like current page, take the help of a JavaScript programmer friend if needed for help.

Also note that the best practice is to avoid JS code and loops as far as possible: https://github.com/intuit/karate#loops

Upvotes: 3

Related Questions