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
Variables are ways to hold value or computed values, like in programming language.
13
13
14
-
### Definition
14
+
### Variables
15
15
16
16
Variables can be defined in two ways:
17
17
18
18
1. Variable specification file. Files with `version: default:variable:x.x.x`[**WIP** - not available yet]
19
-
2.`variables` section on a supported specification document. See below.
19
+
2.`variables` section on a supported specification document.
20
20
```yaml
21
21
version: default:http:0.7.2
22
22
@@ -25,8 +25,109 @@ Variables can be defined in two ways:
25
25
var_2: 'value 2'
26
26
...
27
27
```
28
+
3. Variable can be also passed from a command-line invoke. e.g:
29
+
30
+
Say a http spec. file looks following
31
+
32
+
```yaml
33
+
version: default:http:0.7.2
34
+
35
+
variables:
36
+
var1: 22
37
+
38
+
request:
39
+
url: https://someurl.com?var-one={$var1}
40
+
...
41
+
```
42
+
and in the command-line you pass as following
43
+
44
+
```bash
45
+
chk http tests/xkcd-joke.chk var1=23
46
+
```
47
+
48
+
then CHKware will replace `{$var1}` with `23`, before making request
49
+
```yaml
50
+
...
51
+
# url: https://someurl.com?var-one={$var1}
52
+
# to
53
+
url: https://someurl.com?var-one=23
54
+
```
55
+
56
+
However in the command-line you if pass no variable. e.g.
57
+
58
+
```bash
59
+
chk http tests/xkcd-joke.chk
60
+
```
61
+
62
+
then CHKware will replace `{$var1}` with `22` as it's the default value, before making request
63
+
```yaml
64
+
...
65
+
# url: https://someurl.com?var-one={$var1}
66
+
# to
67
+
url: https://someurl.com?var-one=22
68
+
```
69
+
70
+
### Exposable
71
+
72
+
There are some special hidden local variable those are available at runtime of the execution. Those are exposable variables.
73
+
74
+
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.
75
+
76
+
For example:
77
+
78
+
- `$_response`is a local variable that is available in both http and testcase specifications. This special local variable named `_response` get added after the response received successfully.
79
+
80
+
These nodes are available under `$_response` are `version`, `code`, `reason`, `headers`, `body`.
81
+
82
+
Therefore, to access `code` you're supposed to use `$_response.code`.
83
+
84
+
- `$_response.code`holds response status code. e.g. 200, 400, 401, etc
- `$_response.version`holds response HTTP version. e.g. 'HTTP/1.1'
89
+
90
+
- `$_assertion_results`is a local variable that is available in testcase specifications. This special local variable named `_assertion_results` get added to local variable stack after all the assertion is resolved. `_assertion_results` holds a list of objects.
91
+
92
+
Each objects those `$_assertion_results` can hold have following nodes: `name`, `name_run`, `actual_original`, `is_success`, `message`, `assert_fn`
93
+
94
+
Therefore, to access `actual_original` you're supposed to use `$_assertion_results.1.actual_original`.
95
+
96
+
- `$_assertion_results.name`stores name of the assertion
97
+
- `$_assertion_results.name_run`stores name of the specific name and run, this uniquely identifies and assertion
98
+
- `$_assertion_results.actual_original`original variable that was supposed to be asserted
99
+
- `$_assertion_results.is_success`stores the boolean result of the
100
+
- `$_assertion_results.message`stores the error message if the assertion fails
101
+
- `$_assertion_results.assert_fn`stores the assertion function used when assertion fails
102
+
103
+
#### `expose` node
104
+
105
+
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.
106
+
107
+
For example to expose response data after the request have been executed and got response successfully. eg:
0 commit comments