v1.5
✨✨✨FEATURE✨✨✨
- Support set next request in the test script
- Support custom report names
- Now the test reports are always generated
Now rest-cli add a new defined variable REST_CLI
, so you can using the if
check to run the function that only supported by rest-cli. For now, it is setNextRequest
and we will add more functions in the future.
Let see the script test bellow:
### Request with name request1
# @no-redirect
# @name=request1
GET https://httpbin.org/status/200
> {%
client.log("Log in request1; next = request3")
if (typeof REST_CLI !== 'undefined') client.setNextRequest("request3");
%}
### Request with name request2
# @name=request2
GET https://httpbin.org/status/404
> {%
client.log("Log in request2; next = _END_")
if (typeof REST_CLI !== 'undefined') client.setNextRequest("_END_");
%}
### Request with name request3
# @name=request3
GET https://httpbin.org/get
> {%
client.log("Log in request3; next = null")
%}
### Request with name request4
# @name=request4
GET https://httpbin.org/get
> {%
client.log("Log in request4; next = request2")
if (typeof REST_CLI !== 'undefined') client.setNextRequest("request2");
%}
###
So, there is a new syntax to define a request name:
# @name=request3
Then, in the test script, we can call the rest-cli function - setNextRequest
to tell the rest-cli which request will be executed next.
Here are the specs for setNextRequest:
- We have 10 requests named request0, request1,....,request10.
- By default, the requests are executed by order from request0 to request10.
- Suppose we execute request5, ff in the test script we
setNextRequest("request7")
, then the next request will be request7. If in the request7 there is no define next request -> it will continue running by sequence (request8, request9, request10). - If we call setNextRequest("END") => the executor will be finished (the request after will be not run).
We now also support custom report names too.
The report names must separate by ':' character; If the split string of the report name is empty, then the test request file name will be used for the report name. Such as:
java -jar restcli.jar -r custom_report1::custom_report3 test1.http test2.http test3.http
Then the test report for test1.http
will be custom_report1.xml
; test2.http -> test2.xml
(Because the report name for test2.http is empty); test3.http -> custom_report3.xml
FAQ
Q: Why do we need setNextRequest
function?
A: setNextRequest
function will make our test script more flexible. We can create a custom flow for our test script. For example in request1, we can know the user status (may be registered or not). If the user registered, we will move the next request to request name login
, otherwise, move the next request to request name register
.
Q: What if there are multiple setNextRequest
calls in the test script?
A: The last call will be used. Also, keep in mind that setNextRequest
does not execute the next request immediately. It only executes after the current request is finished.
Q: How do I stop the executor from the current request?
A: You just need to call setNextRequest("_END_")
or setNextRequest(_END_)
(The _END_
variable is defined in the rest-cli.