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/sources/k6/next/using-k6/test-authoring/create-test-script-using-the-cli.md
+10-2
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ Writing a k6 test script from scratch can seem challenging if you're just gettin
13
13
To use the k6 `new` command, you'll need:
14
14
15
15
-[k6 v0.57 or higher](https://grafana.com/docs/k6/<K6_VERSION>/set-up/install-k6/) installed on your machine.
16
+
- Custom templates require k6 v1.0.0-rc1 or higher.
16
17
17
18
## Use the k6 new command
18
19
@@ -43,16 +44,23 @@ The options are:
43
44
-`minimal`: Creates a minimal test script with a short options configuration, and a single request and check example. This is the default option.
44
45
-`protocol`: Creates a script that includes environment variables, stages with different durations and VUs, thresholds, and a setup function. This is ideal for learning, and as a good starting point for real-world scenarios.
45
46
-`browser`: Creates a browser script that checks if a websites successfully loaded, looks for elements on the screen, and takes a screenshot. Similar to the `protocol` option, this is ideal for learning, and a good starting point for creating browser tests.
47
+
- An absolute or a relative path to a local file, such as `./my-template.js` or `/path/to/my-template.js` to use a custom template. `k6` uses [Go templating syntax](https://pkg.go.dev/text/template#section-documentation) to render the script.
46
48
47
-
To use the template flag, run:
49
+
To generate a script using a template, run:
48
50
49
51
```bash
50
52
k6 new --template protocol
51
53
```
52
54
53
55
### --project-id
54
56
55
-
The `--project-id` allows you to specify a Grafana Cloud k6 project ID. The generated script is then configured to run in that project.
57
+
The `--project-id` flag allows you to specify a Grafana Cloud k6 project ID. The generated script is then configured to run in that project. To include the project ID in your custom template, use `{{ .ProjectID }}` as a placeholder, for example:
58
+
59
+
```javascript
60
+
exportdefaultfunction () {
61
+
console.log('Hello from project {{ .ProjectID }}!');
0 commit comments