-
Notifications
You must be signed in to change notification settings - Fork 9
/
addPet.feature
104 lines (94 loc) · 2.48 KB
/
addPet.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@openapi-file=petstore-openapi.yml
Feature: Add a new pet to the store
Add a new pet to the store
Background:
* url baseUrl
@operationId=addPet
Scenario Outline: Test addPet for <status> status code
* def args = read(<testDataFile>)
* def result = call read('addPet.feature@operation') args
* match result.responseStatus == <status>
Examples:
| status | testDataFile |
| 200 | 'test-data/addPet_200.yml' |
| 400 | 'test-data/addPet_400.yml' |
@operationId=addPet
Scenario: explore addPet inline
You may use this test for quick API exploratorial purposes.
* def payload =
"""
{
"statusCode": 200,
"headers": {},
"params": {},
"body": {
"id": 10,
"name": "doggie",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"fill some value"
],
"tags": [
{
"id": 0,
"name": "fill some value"
}
],
"status": "sold"
},
"matchResponse": true
}
"""
* call read('addPet.feature@operation') payload
@ignore
@operation @operationId=addPet @openapi-file=petstore-openapi.yml
Scenario: operation PetApi/addPet
* def args =
"""
{
auth: #(karate.get('auth')),
headers: #(karate.get('headers')),
params: #(karate.get('params')),
body: #(karate.get('body')),
statusCode: #(karate.get('statusCode')),
matchResponse: #(karate.get('matchResponse'))
}
"""
* def authHeader = call read('classpath:karate-auth.js') args.auth
* def headers = karate.merge(args.headers || {}, authHeader || {})
Given path '/pet'
And headers headers
And request args.body
When method POST
# validate status code
* if (args.statusCode && responseStatus != args.statusCode) karate.fail(`status code was: ${responseStatus}, expected: ${args.statusCode}`)
# validate response body
* if (args.matchResponse === true) karate.call('addPet.feature@validate')
@ignore @validate
Scenario: validates addPet response
* def responseMatch =
"""
{
"id": "##number",
"name": "#string",
"category": {
"id": "##number",
"name": "##string"
},
"photoUrls": "#array",
"tags": "##array",
"status": "##string"
}
"""
* match response contains responseMatch
# validate nested array: photoUrls
* def photoUrls_MatchesEach = "##string"
* def photoUrls_Response = response.photoUrls || []
* match each photoUrls_Response contains photoUrls_MatchesEach
# validate nested array: tags
* def tags_MatchesEach = {"id":"##number","name":"##string"}
* def tags_Response = response.tags || []
* match each tags_Response contains tags_MatchesEach