Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

karate - for the data-driven feature, doest it support an normal array looping, not json array?

I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array

As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.

Here is my string(separated by ',') that needs to get passed as request parameter:

   "PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"

Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:

* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list

So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...