Response analysis and parsing
Some actions have a responses key that allows you to parse the result sent by the server.
This parsing operation is useful if you want to populate variables or simply check if the returned results are the expected ones !
Depending on the action type, data extraction can be done using regexp, jsonpath or xmlpath !
HTTP response parsing
You can extract data from the response body or from a HTTP Header.
regex, jsonpath or xmlpath can be used to collect the substrings.
Here is an example which uses regular expression (OPT means optional and MAND means mandatory):
- http:
title: Page 4
method: POST
use_http2: true
url: http://server/page4.php # variables are interpolated in URL, but only
# for the URI part (not the server name)
body: name=${name}&age=${age} # MAND for POST http action
headers:
accept: "text/html,application/json" # variables are interpolated in Headers
content-type: text/html
responses: # OPT
- regex: "is: (.*)<br>" # MAND must be one of regex/jsonpath/xmlpath
index: first # OPT must be one of first (default)/last/random
variable: address # MAND
default_value: bob # used when the regex failed (can be a string or an int)
- from_header: Via # OPT HTTP Header name to extract the value from
regex: "(.*)" # MAND
index: first # OPT must be one of first (default)/last/random
variable: proxy_via # MAND
default_value: - # used when the regex failed
Here is an example which uses jsonpath:- http:
title: Page 6
method: POST
url: http://server/page4.php
body: name=${name}&age=${age}
responses:
- jsonpath: $.name+
index: first
variable: name
default_value: bob
MongoDB response parsing
Data can be extracted from server responses when the findone command is played.
jsonpath can be used to collect the substrings:
- mongodb:
title: Recherche
server: mongodb://server:27017
database: testing
collection: person
command: findone
filter: '{"age": { "$eq": 30}}'
responses:
- jsonpath: $.name+
variable: the_name
index: first
default_value: alice
Elasticsearch response parsing
Data can be extracted from server responses when the search command is played.
jsonpath can be used to collect the substrings:
- elasticsearch:
title: Recherche
server: http://server:9200
index: testing
command: search
query: '{"query": {"match_all": {}}}'
responses:
- jsonpath: $.hits.total.value+
index: first
variable: hits
default_value: not_found
WebSocket response parsing
Data can be extracted from server responses. The extraction can use the body or a HTTP Header.
regex, jsonpath or xmlpath can be used to collect the substrings.
The examples are similar to the HTTP ones.
gRPC response parsing
Data can be extracted from server responses. The response is considered as a JSON document
so only jsonpath is supported.
- grpc:
title: Hello
call: chat.ChatSerice.SayHello
data: '{"body": "hello !"}'
responses:
- jsonpath: $.body+
variable: name
index: first
default_value: alice