Skip to main content

k6 new

Create and initialize a new k6 script using one of the predefined templates.

Synopsis

Description

The k6 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

string
default:"script.js"
The name of the script file to create

Examples

Flags

boolean
Overwrite existing files without prompting
string
default:"minimal"
Template type to use. Available options:
  • minimal - Basic k6 test script
  • protocol - Protocol-level testing template
  • browser - Browser automation template
  • Path to a custom template file (relative or absolute)
string
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 --force is not specified
  • The specified template doesn’t exist or is invalid
  • There are file system permission issues

See Also

  • k6 run - Run your newly created test
  • k6 cloud - Run tests in Grafana Cloud