You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above testcase spec. doc define a request that makes a `POST` call to `https://reqres.in/api/users` URL with a body `{"name": "My Name", "job": "My Job"}`.
37
+
38
+
After the request server responses with following:
- The response code is 201, or the resource was created
45
+
- The response if a map / dictionary
46
+
47
+
Assertion [reference with examples](/references/testcase-reference#assertions) can be found here.
48
+
49
+
### A minimal Testcase with out-file request
50
+
51
+
A http spec. doc can be written on separate file, that does same as above request. Let's call it `same-request.chk`. The http spec. doc by default exposes `$_response` object.
19
52
20
53
```yaml
54
+
# file: same-request.chk
55
+
---
56
+
version: 'default:http:0.7.2'
57
+
58
+
request:
59
+
url: "https://reqres.in/api/users"
60
+
method: POST
61
+
body[json]: {
62
+
'name': My Name,
63
+
'job': My Job,
64
+
}
65
+
```
66
+
67
+
Now we can point out above file to execute before make assertions like below (assuming both file lives on same directory).
Please notice the `$_response` in the testcase doc. This variable is available after the request gets executed as local variable.
83
+
84
+
### A Testcase with out-file request passing data
85
+
86
+
To pass data from a testcase spec. doc to a http spec. doc, we first need to add some variables. These variables can also have some default value. Say in the following case, we defined `name` and `job` variables with default value. So, if no value passed these values will be passed to server as part of request body.
87
+
88
+
```yaml
89
+
# file: same-request.chk
90
+
---
91
+
version: 'default:http:0.7.2'
92
+
24
93
variables:
25
-
Name: 'Morpheus'
26
-
Job: 'leader'
27
-
Response: ~
28
-
Server: https://reqres.in/api/v1
94
+
name: My Name
95
+
job: My Job
29
96
30
97
request:
31
-
url: "{$Server}/users"
98
+
url: "https://reqres.in/api/users"
32
99
method: POST
33
100
body[json]: {
34
-
'name': $Name,
35
-
'job': $Job,
101
+
'name': $name,
102
+
'job': $job,
36
103
}
37
-
return: ~
104
+
```
105
+
106
+
Now we can point out which value we want to pass using `with` statement in `execute` block.
Copy file name to clipboardExpand all lines: docs/tutorials/feature-test.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Let's continue to test our [_XKCD.com JSON API http client_](/tutorials/http-cli
55
55
56
56
Let us go through the testcase spec. we wrote. If you call the API `https://xkcd.com/614/info.0.json` in any Firefox, the response will be shown like this:
0 commit comments