k6 new
Create and initialize a new k6 script using one of the predefined templates.Synopsis
Description
Thek6 new command creates a new test script from a template. By default, it creates a file named script.js unless a different filename is specified.
This command helps you quickly get started with k6 by providing pre-configured templates for common testing scenarios.
Arguments
The name of the script file to create
Examples
Flags
Overwrite existing files without prompting
Template type to use. Available options:
minimal- Basic k6 test scriptprotocol- Protocol-level testing templatebrowser- Browser automation template- Path to a custom template file (relative or absolute)
Specify the Grafana Cloud project ID for the test. This pre-configures the script for cloud execution.
Template Types
minimal
The minimal template creates a simple load test with basic HTTP requests. This is ideal for getting started quickly.protocol
The protocol template includes examples of various HTTP methods, request configuration, and response validation.browser
The browser template sets up a browser-based test using k6’s browser testing capabilities.Custom Templates
You can also provide a path to your own custom template file:Output
When successful, the command outputs:Error Handling
The command will fail if:- The target file already exists and
--forceis not specified - The specified template doesn’t exist or is invalid
- There are file system permission issues