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
Copy file name to clipboardExpand all lines: README.md
+55-20
Original file line number
Diff line number
Diff line change
@@ -82,13 +82,19 @@ The configuration file looks like the following:
82
82
83
83
A Server description contains various fields:
84
84
85
-
-`host`: the URL of the server (including port and everything you don't want to repeat on every test)
86
-
-`auth.login`: the information required to login the user, using the same format as a test (see below)
87
-
-`auth.session.cookie`: name of the cookie maintaining the session
85
+
-`host` (mandatory): the URL of the server (including port and everything you don't want to repeat on every test)
86
+
87
+
-`auth.login`: used for login/password authentication, using the same format as a test (see below)
88
+
89
+
-`auth.session.cookie`: used for cookie session management, name of the cookie maintaining the session
90
+
91
+
-`auth.apikey`: used for API Key authentication, contains both the API Key and the required header
92
+
93
+
-`auth.session.jwt`: used for JWT session management (`header`, `payload` or `payload.xxx`)
88
94
89
95
Here `exampleserver1` uses the `/login` endpoint on the same HTTP server than the one used for the tests. Both `email` and `password` are submitted in the `POST`, and `200 OK` is expected upon successful login. The session is maintained by a session cookie called `jsessionid`.
90
96
91
-
The second server, `exampleserver2` also uses the `/login` endpoint, but on a different server, hence the fully qualified URL given as the endpoint. The sesssion is maintained using a JWT (JSON Web Token) which is obtained though a header (namely `Authorization`). Should your JWT be returned as a payload, you can specify `"payload"` instead of `"header"`. You can even use `payload.token` for instance, if your JWT is returned in a `token` field of a JSON object. JWT is always sent back using the `Authorization` header in the form of `Authorization: Bearer my_jwt`.
97
+
The second server, `exampleserver2` also uses the `/login` endpoint, but on a different server, hence the endpoint with a different server. The sesssion is maintained using a JWT (JSON Web Token) which is obtained though a header (namely `Authorization`). Should your JWT be returned as a payload, you can specify `"payload"` instead of `"header"`. You can even use `payload.token` for instance, if your JWT is returned in a `token` field of a JSON object. JWT is always sent back using the `Authorization` header in the form of `Authorization: Bearer my_jwt`.
92
98
93
99
> Please note that in the case of the server definition, `endpoint` must be an fully qualified URL, not a relative endpoint like in the test files. Thus `endpoint` must start with `http://` or `https://`.
94
100
@@ -162,26 +168,35 @@ A test file looks like the following:
162
168
163
169
A test file contains an array of tests, each of them containing:
164
170
165
-
-`name`: a unique name to globally identify the test (test name must not contain the `. (period)` character)
166
-
-`server`: the name of the server used to perform the test (declared in the configuration file)
167
-
-`method`: the method to perform the operation (`GET`, `POST`, `PUT`, etc.)
168
-
-`endpoint`: the endpoint of the operation (usually a ReST API of some sort)
169
-
-`capture`: true if you want to capture the response of this test so that it can be used in another test in this file (fileParallel mode only)
170
-
-`skip`: true to have okapi skip this test (useful when debugging a script file)
171
-
-`payload`: the payload to be sent to the endpoint (usually with a POST, PUT or PATCH method). This field is optional
171
+
-`name` (mandatory): a unique name to globally identify the test (test name must not contain the `. (period)` character)
172
+
173
+
-`server` (mandatory): the name of the server used to perform the test (declared in the configuration file)
174
+
175
+
-`method` (mandatory): the method to perform the operation (`GET`, `POST`, `PUT`, etc.)
176
+
177
+
-`endpoint` (mandatory): the endpoint of the operation (usually a ReST API of some sort)
178
+
179
+
-`capture` (default false): true if you want to capture the response of this test so that it can be used in another test in this file (fileParallel mode only)
180
+
181
+
-`skip` (default false): true to have okapi skip this test (useful when debugging a script file)
182
+
183
+
-`payload` (default none): the payload to be sent to the endpoint (usually with a POST, PUT or PATCH method)
184
+
172
185
-`expected`: this section contains:
173
-
-`statuscode`: the expected status code returned by the endpoint (200, 401, 403, etc.)
174
-
-`response`: the expected payload returned by the endpoint. This field is optional
175
186
176
-
> Please note that `payload` and `response` can be either a string (including json, as shown in 121004), or `@file` (as shown in 121005) or even a `@custom_filename.json` (as shown in doesnotwork). This is useful if you prefer to separate the test from its `payload` or expected `response`. This is particularly handy if the `payload` or `response` are complex JSON structs that you can easily copy and paste from somewhere else, or simply prefer to avoid escaping double quotes.
187
+
-`statuscode` (mandatory): the expected status code returned by the endpoint (200, 401, 403, etc.)
188
+
189
+
-`response` (default none): the expected payload returned by the endpoint. This field is optional
190
+
191
+
> Please note that `payload` and `response` can be either a string (including json, as shown in 121004), or `@file` (as shown in 121005) or even a `@custom_filename.json` (as shown in doesnotwork). This is useful if you prefer to separate the test from its `payload` or expected `response` (for instance, it is handy if the `payload` or `response` are complex JSON structs that you can easily copy and paste from somewhere else, or simply prefer to avoid escaping double quotes). However, keeping the names for `payload` and `response` like `test_name.payload.json`and `test_name.expected.json` is still a good practice.
177
192
178
193
> Please also note that `endpoint` and `payload` can use environment variable substitution using the ${env:XXX} syntax (see previous note about environment variable substitution).
179
194
180
195
> Lastly, please note that `endpoint` and `response` can use captured variable (i.e. variables inside a captured response, see `"capture":true`). For instance, to use the `id` field returned inside of a `user` object in test `mytest`, you will use `${mytest.user.id}`. In the example above, we used `${cap121004.id}` to retrieve the ID of the returned response in test `cap121004`. Captured response also works with arrays.
181
196
182
197
### Payload and Response files
183
198
184
-
Payload and response files don't have a specific format, since they represent whatever the server you are testing is expecting from or returns to you. The only important things to know about the payload and response files, is that they must be placed in the test directory, and must be named `<name_of_test>.payload.json` and `<name_of_test>.expected.json` (`121005.expected.json` in the example above) respectively if you specify `@file`. If you decide to use a custom filename for your `payload` and/or `response`, then you can specify the name of your choice prefixed by `@` (`@custom_filename.json` in the example above).
199
+
Payload and response files don't have a specific format, since they represent whatever the server you are testing is expecting from or returns to you. The only important things to know about the payload and response files, is that they must be placed in the test directory, and must be named `<name_of_test>.payload.json` and `<name_of_test>.expected.json` (`121005.expected.json` in the example above) respectively if you specify `@file`. Alternatively, they can also be put in a `payload/` or `expected/` subdirectory of the test directory, and, in that case, be named `<name_of_test>.json`. If you decide to use a custom filename for your `payload` and/or `response`, then you can specify the name of your choice prefixed by `@` (`@custom_filename.json` in the example above).
185
200
186
201
## Expected response
187
202
@@ -194,6 +209,8 @@ As we saw earlier, for each test, you will have to define the expected response.
194
209
- if the response is a non-JSON string:
195
210
- the response is compared to `expected` and success or failure is reported
196
211
212
+
> Please note that, in the case of non-JSON responses, you can use the `%` character to match start, end or part of the response, pretty much like in SQL. For instance, expected responses like `"%test"`, `"test%"` and `"%test%"` will match test at the beginning, end or as part of the returned response respectively.
213
+
197
214
## Running okapi :giraffe:
198
215
199
216
To launch okapi, please run the following:
@@ -205,23 +222,40 @@ To launch okapi, please run the following:
205
222
where options are one or more of the following:
206
223
207
224
-`--servers-file`, `-s` (mandatory): point to the configuration file's location
208
-
-`--timeout` (default 30s): set a default timeout for all HTTP requests
-`--no-parallel` (default parallel): prevent tests from running in parallel
227
+
211
228
-`--file-parallel` (default no): run the test files in parallel (instead of the tests themselves)
229
+
230
+
-`--file` (default none): only run the specified test file
231
+
232
+
-`--test` (default none): only run the specified standalone test
233
+
234
+
-`--timeout` (default 30s): set a default timeout for all HTTP requests
235
+
236
+
-`--no-parallel` (default parallel): prevent tests from running in parallel
237
+
212
238
-`--user-agent` (default okapi UA): set the default user agent
239
+
213
240
-`--content-type` (default application/json): set the default content type for requests
241
+
214
242
-`--accept` (default application/json): set the default accept header for responses
215
-
-`test_directory`: point to the directory where all the test files are located
243
+
244
+
-`test_directory` (mandatory): point to the directory where all the test files are located
216
245
217
246
> Please note that the `--file-parallel` mode is particularly handy if you want to have a sequence of tests that needs to run in a specific order. For instance, you may want to create a resource, update it, and delete it. Placing these three tests in the same file and in the right order, and then running okapi with `--file-parallel` should do the trick. The default mode is used for unit tests, whereas the `--file-parallel` mode is used for (complex) test scenarios.
218
247
219
248
## Output example
220
249
221
-
If you run okapi in verbose mode with the HackerNews API tests, you should get the following outout:
250
+
To try the included examples (located in `./assets/tests`), you need to run the following command:
0 commit comments