简体   繁体   中英

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

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: 特征文件 Here is the query file: 在此处输入图像描述

Any help would be appreciated, thanks.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM