1

I'm trying to convert an Array to string using a simple js function placed in the reusable feature file. I don't see any reason why the array is not getting converted to a string when I try to run the same function on the console it works without any issue. Can anyone suggest a way to get this issue sorted?

"""
* def formatter = function(str){
  var formatstring = str.toString();
   return formatstring
}
 """
feature file 

 * def format = call read('../common/resuable.feature)
 * def result = format.formatter(value)
 * print result


Input = ["ID3:Jigglypuff(NORMAL)"]
Actual result = ["ID3:Jigglypuff(NORMAL)"]
Expected result = ID3:Jigglypuff(NORMAL)


[![When tried same on console][1]][1]


  [1]: https://i.stack.imgur.com/tAcIz.png
User 001
  • 11
  • 2

1 Answers1

0

Sorry, if you print an array, it will have square-brackets and all, that's just how it is.

Please unpack arrays if you want the plain string / content:

* def input = ["ID3:Jigglypuff(NORMAL)"]
* def expected = input[0]
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you, @Peter Thomas, for answering. Although I am trying to print the output of a function, i.e. result, the output string still contains braces. Could you please suggest a way to achieve convert an array of elements to a string – User 001 Jun 05 '21 at 09:12
  • @User001 please look at the ways you can loop in karate. if that doesn't help, please consider what you want as un-supported and look for another framework: https://github.com/intuit/karate#json-transforms – Peter Thomas Jun 05 '21 at 16:10