Summary| Tags| Feature: feature/GQL.feature| Sample GQL
Scenario: [1:7] Sample GQL Request
ms: 1050
>>
Background:
4
* url 'https://countries.trevorblades.com/'
86
5
* def path = karate.properties['user.dir']
140
8
* def file = path + '/src/test/resources/payload/post.graphql'
19
9
* def body = read('file:' + file)
20
10
Given path '/'
0
11
And request {query: #(body)}
64
12
When method POST
704
23:55:07.750 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:55:08.264 response time in milliseconds: 513 1 < 200 1 < Connection: keep-alive 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 < access-control-allow-headers: * 1 < access-control-allow-origin: * 1 < x-powered-by: Stellate 1 < vary: Accept-Encoding 1 < x-timer: S1691798108.236412,VS0,VE1 1 < x-cache-hits: 1 1 < x-cache: HIT 1 < x-served-by: cache-dfw-kdfw8210045-DFW 1 < cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000 1 < content-type: application/json; charset=utf-8 1 < age: 760578 1 < via: 1.1 varnish 1 < date: Fri, 11 Aug 2023 23:55:08 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
12
23:55:08.266 [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'
6
Scenario: [2:17] Sample GQL Request with updated query
ms: 1071
>>
Background:
4
* url 'https://countries.trevorblades.com/'
78
5
* def path = karate.properties['user.dir']
162
18
* def file = path + '/src/test/resources/payload/post2.graphql'
4
19
* def body = read('file:' + file)
29
20
Given path '/'
0
21
* replace body.id = 'IN'
1
22
And request { query: '#(body)' }
59
23
When method POST
711
23:55:07.760 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:55:08.262 response time in milliseconds: 501 1 < 200 1 < Connection: keep-alive 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 < access-control-allow-headers: * 1 < access-control-allow-origin: * 1 < x-powered-by: Stellate 1 < vary: Accept-Encoding 1 < x-timer: S1691798108.247382,VS0,VE2 1 < content-type: application/json; charset=utf-8 1 < x-cache-hits: 1 1 < x-cache: HIT 1 < x-served-by: cache-dfw-kdfw8210061-DFW 1 < age: 759192 1 < via: 1.1 varnish 1 < date: Fri, 11 Aug 2023 23:55:08 GMT 1 < accept-ranges: bytes 1 < cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000 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
26
23:55:08.288 [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'
1