-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcombined_test.tk.yaml
56 lines (53 loc) · 1.97 KB
/
combined_test.tk.yaml
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
---
# Step 1: Simple GET and basic assertions.
- title: "Step 1 - Simple GET and Assertions"
GET: "https://httpbin.org/get"
dump: false
asserts:
# Assert that the status is 200.
- ok: "$.resp.status == 200"
# Assert that the echoed URL is correct.
- string: "$.resp.json.url"
# Assert that the 'args' object exists.
- exists: "$.resp.json.args"
# Assert that the raw response contains the word "httpbin".
- contains: "$.resp.raw ~ httpbin"
# Step 2: Multi-match assertions with numbers.
- title: "Step 2 - Multi-match with Numbers"
GET: "https://jsonplaceholder.typicode.com/posts"
dump: false
asserts:
# Ensure the request succeeded.
- ok: "$.resp.status == 200"
# Assert that the response JSON is an array.
- array: "$.resp.json"
# Assert that the array is not empty.
- notEmpty: "$.resp.json"
# Assert that all elements' 'id' fields are numbers.
- numberAll: "$.resp.json[*].id"
# Assert that at least one element's 'userId' field is a number.
- numberAny: "$.resp.json[*].userId"
# Step 3: Edge Case – Invalid JSONPath.
- title: "Step 3 - Edge Case: Invalid JSONPath"
GET: "https://httpbin.org/get"
dump: false
asserts:
# This JSONPath does not exist and should trigger an error.
- ok: "$.resp.nonexistent == 0"
# Step 4: Hooks Testing.
- title: "Step 4 - Hooks Testing with POST"
POST: "https://httpbin.org/post"
headers:
Content-Type: "application/json"
json:
test: "hook"
# Pre-request hook: Simply returns a message that is logged.
pre_request_hook: "let msg = 'Pre-hook executed'; msg"
# Post-response hook: Checks the status code and returns a message.
post_response_hook: "let status = _.resp.status; if (status == 200) { 'Post-hook: OK' } else { 'Post-hook: Fail' }"
dump: false
asserts:
# Verify that the status code is 200.
- ok: "$.resp.status == 200"
# Verify that the default header (X-Testkit-Run) is present.
- string: "$.resp.json.headers['X-Testkit-Run']"