Scenario: [1:7]
Sample GQL Request
ms: 931
>>
Background:
4
* url 'https://countries.trevorblades.com/'
67
5
* def path = karate.properties['user.dir']
107
8
* def file = path + '/src/test/resources/payload/post.graphql'
15
9
* def body = read('file:' + file)
26
10
Given path '/'
1
11
And request {query: #(body)}
65
12
When method POST
597
23:37:49.885 request:
1 > POST https://countries.trevorblades.com/
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 173
1 > Host: countries.trevorblades.com
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_382)
1 > Accept-Encoding: gzip,deflate
{"query":"query GetCountry {\n country(code: \"BR\") {\n name\n native\n capital\n emoji\n currency\n languages {\n code\n name\n }\n }\n}"}
23:37:50.311 response time in milliseconds: 426
1 < 200
1 < Connection: keep-alive
1 < content-type: application/json; charset=utf-8
1 < stellate-query-hash: 7704063803816850
1 < access-control-max-age: 600
1 < access-control-expose-headers: *
1 < access-control-allow-credentials: true
1 < access-control-allow-methods: POST, GET, HEAD, OPTIONS
1 < cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000
1 < access-control-allow-headers: *
1 < access-control-allow-origin: *
1 < x-powered-by: Stellate
1 < vary: Accept-Encoding
1 < x-timer: S1691797070.305891,VS0,VE2
1 < x-cache-hits: 1
1 < x-cache: HIT
1 < x-served-by: cache-iad-kiad7000142-IAD
1 < age: 1392
1 < via: 1.1 varnish
1 < date: Fri, 11 Aug 2023 23:37:50 GMT
1 < accept-ranges: bytes
1 < gcdn-cache: HIT
{"data":{"country":{"name":"Brazil","native":"Brasil","capital":"Brasília","emoji":"🇧🇷","currency":"BRL","languages":[{"code":"pt","name":"Portuguese"}]}}}
13
Then status 200
0
14
And print response
19
23:37:50.327 [print] {
"data": {
"country": {
"name": "Brazil",
"native": "Brasil",
"capital": "Brasília",
"emoji": "🇧🇷",
"currency": "BRL",
"languages": [
{
"code": "pt",
"name": "Portuguese"
}
]
}
}
}
15
And match response.data.country.name == 'Brazil'
35
Scenario: [2:17]
Sample GQL Request with updated query
ms: 942
>>
Background:
4
* url 'https://countries.trevorblades.com/'
67
5
* def path = karate.properties['user.dir']
106
18
* def file = path + '/src/test/resources/payload/post2.graphql'
10
19
* def body = read('file:' + file)
36
20
Given path '/'
13
21
* replace body.id = 'IN'
7
22
And request { query: '#(body)' }
48
23
When method POST
609
23:37:49.886 request:
1 > POST https://countries.trevorblades.com/
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 173
1 > Host: countries.trevorblades.com
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_382)
1 > Accept-Encoding: gzip,deflate
{"query":"query GetCountry {\n country(code: \"IN\") {\n name\n native\n capital\n emoji\n currency\n languages {\n code\n name\n }\n }\n}"}
23:37:50.321 response time in milliseconds: 435
1 < 200
1 < Connection: keep-alive
1 < content-type: application/json; charset=utf-8
1 < stellate-query-hash: 5293100588979637
1 < access-control-max-age: 600
1 < access-control-expose-headers: *
1 < access-control-allow-credentials: true
1 < access-control-allow-methods: POST, GET, HEAD, OPTIONS
1 < cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000
1 < access-control-allow-headers: *
1 < access-control-allow-origin: *
1 < x-powered-by: Stellate
1 < vary: Accept-Encoding
1 < x-timer: S1691797070.317410,VS0,VE1
1 < x-cache-hits: 1
1 < x-cache: HIT
1 < x-served-by: cache-iad-kiad7000127-IAD
1 < age: 1392
1 < via: 1.1 varnish
1 < date: Fri, 11 Aug 2023 23:37:50 GMT
1 < accept-ranges: bytes
1 < gcdn-cache: HIT
{"data":{"country":{"name":"India","native":"भारत","capital":"New Delhi","emoji":"🇮🇳","currency":"INR","languages":[{"code":"hi","name":"Hindi"},{"code":"en","name":"English"}]}}}
24
Then status 200
0
25
And print response
6
23:37:50.326 [print] {
"data": {
"country": {
"name": "India",
"native": "भारत",
"capital": "New Delhi",
"emoji": "🇮🇳",
"currency": "INR",
"languages": [
{
"code": "hi",
"name": "Hindi"
},
{
"code": "en",
"name": "English"
}
]
}
}
}
26
And match response.data.country.name == 'India'
40