How can I use data driven testing in graphQL using variables and objects?:
Hey all,
I’m trying to implement data driven testing in my project. We’re using graphql and some of the queries/mutations has very large and tricky variables, there are not only key:values,. there are also objects that contains one or more parameters. I can run the tests without any issue if I only set the parameters outside of the objects, but when I try to use the ones inside of the objects I got a 400 error
Data:
Variables in graphql query in postman UI
{
“object1”: {
“parameter1”: {{parameter1}},
“parameter2”: {{parameter2}}
},
“object2”: {
“parameter3”: {{parameter3}}
},
“parameter4”: {{parameter4}},
“parameter5”: {{parameter5}},
“object3”: {
“parameter6”: {{parameter6}},
“parameter7”: {{parameter7}}
}
}
Json file
[
{
"parameter1": "value1",
"parameter2": "value2",
"parameter3": "value3",
"parameter4": "value4",
"parameter5": value5(int),
"parameter6": value6(boolean),
"parameter7": value7(int)
}
]
How I found the problem:
When I ran the graphql query using the json file I checked the console and I check the error in the response body
{“message”:“Unexpected token D in JSON at position 2336”,“error”:{“expose”:true,“statusCode”:400,“status”:400,“body”:"{“query”:“query testSomething(variables declaration) {\n other parameters…) “,“variables”:{\n\t\t"object1”: {\n\t\t\t"parameter1”: value1,\n\t\t\t"parameter2": value2\n\t\t},\n\t\t"object2": {\n\t\t\t"parameter3": value3\n\t\t},\n\t\t"parameter4": value4,\n\t\t"parameter5": value5,\n\t\t"object3": {\n\t\t\t"parameter6": value6,\n\t\t\t"parameter7": value7\n\t\t}\n}}",“type”:“entity.parse.failed”}}
I’ve already tried:
I changed the json file, adding the objects and I got the same error. Also I tried using csv file. Same error.