Karate DSL: How to pass Scenario Outline variables into a json string

Viewed 14

I'm testing a graphQL endpoint. I want to keep the query separate from the feature file so that it can be reused elsewhere. The query has an embedded string which I want to pass in variables from my examples, however, I can't seem to update the query.

Here is the feature file: feature file Here is the query file: enter image description here

Any help would be appreciated, thanks.

1 Answers

I think best practice is to read the query part alone as a text file, and then form the JSON within the test. Your JSON is actually not well-formed because JSON does not allow line-feeds within values, that's why you have the red squiggly line in your screen shot.

Refer articles like this: https://www.katk.dev/graphql-karate

Best practice is to use the variables in the JSON in addition to the query. If not, be aware that you can do placeholder substitution in plain-text using Karate: https://github.com/karatelabs/karate#replace

Also read this part of the documentation: https://github.com/karatelabs/karate#dont-parse-treat-as-raw-text

Related