Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

How to add a dynamic variable value inside a param field as a String in Karate?

I have an API, wherein the Param field, I need to pass the current date as a string.

And param filter = 'ORDER_DATE:"2021-01-31"'

I am trying to pass the current date for the ORDER_DATE field form a java method:

* def todaysDate = helper.getTodaysDate()

And print todaysDate // Prints 2021-02-04

Now I need to pass this "todaysDate " valuein the param filter field.

Following what I have tried so far:

And param filter = 'ORDER_DATE:#(todaysDate )' 
And param filter = 'ORDER_DATE:<todaysDate>'

From example table value.

In Both cases, it printed "todaysDate " instead of its value "2021-02-04"

question from:https://stackoverflow.com/questions/66050838/how-to-add-a-dynamic-variable-value-inside-a-param-field-as-a-string-in-karate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is just JavaScript:

And param filter = 'ORDER_DATE:"' + todaysDate + '"'

This can improve in the 1.0 version BTW:

And param filter = `ORDER_DATE:"${todaysDate}"`

Further reading: https://github.com/intuit/karate#rules-for-embedded-expressions


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...