Search code examples
cucumberkaratecucumber-jvmcucumber-java

Custom type conversion in Karate


As Karate supports type conversion, I was wondering if it is possible to write a custom type conversion in such a way that I could write something similar to this in my .feature file

customType customTypeResponse = response

which should have the same semantic as

yaml yamlResponse = response

but for customType instead of yaml.

I think I found the code enabling the custom type conversion. But I am not sure about the extensibility.

Thus the shortest way might be to use the Java interop enabling something like this

def customTypeResponse = CustomType.convert(response)

Please let me know of any possibiliy of type conversion.


Solution

  • Yes, I strongly suggest just using Java interop and not complicating it further for now. Maybe in the future we'll have a better way to do contribute custom syntax (hint: look for the Plugin interface and how karate-robot uses it).