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: docs/cli-usage.md
+57-9
Original file line number
Diff line number
Diff line change
@@ -166,26 +166,74 @@ httpprobe run --verbose
166
166
167
167
## Environment Variables
168
168
169
-
HttpProbe can load environment variables from a file specified with `--envfile`. These variables can be accessed in your test definitions using the `${ENV:VARIABLE_NAME}` syntax.
169
+
HttpProbe can load environment variables from a file specified with `--envfile`. These variables can be accessed in your test definitions using the `${env:VARIABLE_NAME}` syntax.
170
170
171
-
For example, if your `.env` file contains:
171
+
### Configuration
172
172
173
+
By default, HttpProbe looks for a file named `.env` in the current directory. You can specify a different file using the `--envfile` flag:
174
+
175
+
```bash
176
+
httpprobe run --envfile .env.production
173
177
```
178
+
179
+
### Environment File Format
180
+
181
+
The environment file should use the standard format of one variable per line, with `KEY=VALUE` pairs:
182
+
183
+
```
184
+
# Comments are supported
174
185
API_KEY=secret-key
175
186
BASE_URL=https://api.example.com
187
+
TIMEOUT=30
188
+
```
189
+
190
+
Both single and double quotes are supported and will be stripped from the values:
191
+
176
192
```
193
+
SECRET_KEY='this is a quoted string'
194
+
API_TOKEN="another quoted string"
195
+
```
196
+
197
+
### Using Environment Variables in Tests
177
198
178
-
You can reference these in your test definitions:
199
+
Once loaded, environment variables can be accessed in your test definitions using the `${env:VARIABLE_NAME}` syntax:
179
200
180
201
```yaml
181
-
- name: Get user profile
182
-
request:
183
-
url: ${ENV:BASE_URL}/profile
184
-
headers:
185
-
Authorization: Bearer ${ENV:API_KEY}
202
+
name: API Tests with Environment Variables
203
+
suites:
204
+
- name: Authentication Tests
205
+
cases:
206
+
- title: Test API key authentication
207
+
request:
208
+
url: ${env:BASE_URL}/auth
209
+
headers:
210
+
- key: Authorization
211
+
value: Bearer ${env:API_KEY}
212
+
body:
213
+
type: json
214
+
Data:
215
+
environment: ${env:ENV_NAME}
186
216
```
187
217
188
-
This allows you to keep sensitive information out of your test files and change configurations based on environment.
218
+
### Environment Switching
219
+
220
+
This feature is particularly useful for switching between different environments (development, staging, production) without modifying your test files:
221
+
222
+
```bash
223
+
# Run tests against development environment
224
+
httpprobe run --envfile .env.development
225
+
226
+
# Run tests against production environment
227
+
httpprobe run --envfile .env.production
228
+
```
229
+
230
+
### Best Practices
231
+
232
+
1.**Sensitive Information**: Use environment variables for API keys, tokens, and other sensitive data
233
+
2.**Environment-specific URLs**: Store base URLs and endpoints in environment variables
234
+
3.**Credentials**: Keep usernames, passwords, and other credentials in environment variables
235
+
4.**Multiple Environments**: Create separate .env files for different environments (.env.dev, .env.staging, .env.prod)
236
+
5.**CI/CD Integration**: In CI/CD pipelines, use the appropriate environment file for each environment
0 commit comments