Variable specification reference
- This page should be use as reference for specification files.
- This page is subject to change. It is requested to check this page frequently.
Introduction
Variables are ways to hold value or computed values, like in programming language.
Variables
Variables can be defined in two ways:
- Variable specification file. Files with
version: default:variable:x.x.x[WIP - not available yet] variablessection on a supported specification document.
version: default:http:0.7.2
variables:
var1: value one
var_2: "value 2"
- Variable can be also passed from a command-line invoke. e.g:
Say a http spec. file looks following
version: default:http:0.7.2
variables:
var1: 22
request:
url: https://someurl.com?var-one={$var1}
...
and in the command-line you pass as following
chk http tests/xkcd-joke.chk var1=23
then CHKware will replace {$var1} with 23, before making request
---
# url: https://someurl.com?var-one={$var1}
# to
url: https://someurl.com?var-one=23
However in the command-line you if pass no variable. e.g.
chk http tests/xkcd-joke.chk
then CHKware will replace {$var1} with 22 as it's the default value, before making request
---
# url: https://someurl.com?var-one={$var1}
# to
url: https://someurl.com?var-one=22
Exposable
There are some special hidden local variable those are available at runtime of the execution. Those are exposable variables.
There is one special type of variable block that can be use in a http / testcase specification file to expose these exposable to callee environment. This exposeable section cab be defined with expose node.
For example:
_responseis a local variable that is available in both http and testcase specifications. This special local variable named_responseget added after the response received successfully.These nodes are available under
_responseareversion,code,reason,headers,body.Therefore, to access
codeyou're supposed to use_response.code._response.codeholds response status code. e.g. 200, 400, 401, etc_response.headersholds response headers._response.bodyholds response body._response.reasonholds response reason. e.g. 'Created', 'Moved Permanently', etc more here_response.versionholds response HTTP version. e.g. 'HTTP/1.1'
_assertion_resultsis a local variable that is available in testcase specifications. This special local variable named_assertion_resultsget added to local variable stack after all the assertion is resolved._assertion_resultsholds a list of objects.Each objects those
_assertion_resultscan hold have following nodes:name,name_run,actual_original,is_success,message,assert_fnTherefore, to access
actual_originalyou're supposed to use_assertion_results.1.actual_original._assertion_results.namestores name of the assertion_assertion_results.name_runstores name of the specific name and run, this uniquely identifies and assertion_assertion_results.actual_originaloriginal variable that was supposed to be asserted_assertion_results.is_successstores the boolean result of the_assertion_results.messagestores the error message if the assertion fails_assertion_results.assert_fnstores the assertion function used when assertion fails
expose node
Special block that can used to expose data from callee environment to caller environment. We can write any local variable data to be exposed from this section. expose node expects an array to be written. It also can be left as null.
For example to expose response data after the request have been executed and got response successfully. eg:
expose:
- "{$_response.body}"
- "{$_response.code}"
or after a testcase execution is done
expose: [
"{$_response.body}",
"{$_response.code}",
"{$_assertion_results.2.name_run}",
"{$_assertion_results}",
"{$_response}"
]
# or
expose: ["{$_assertion_results.2.name_run}", "{$_assertion_results.2.is_success}"]