Jawad Kalia
Jawad Kalia

Reputation: 296

How to use variables in a feature file, in a javascript function?

For example i do

* def fooresponse = call read('../getfooid.feature')

* def jsfunction= """(fooresponse){ console.log(fooresponse)}"""

is that possible? what is the recommended way to do it?

Thanks!

edit: fixing js syntax lol

Upvotes: 1

Views: 1646

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Yes, this will work if the function has been defined after the variable fooresponse:

* def jsfunction = function(){ karate.log(fooresponse) }

Yes, you can pass a single argument to karate.call().

Keep in mind that the #(foo) substitution does NOT apply to pure-JS, explained here: https://github.com/intuit/karate#karate-expressions

I think once you read the above link AND if you are familiar with JS, you will know what to do.

Like this:

* def fun = function(){ karate.call('foo.feature', { bar: 'baz' }) }

Upvotes: 2

Related Questions