Understand when to use Script Authoring mode
Before you generate your first script, build a simple mental model for where Script Authoring mode fits in your workflow. It helps you bootstrap and refine scripts, while you still review and own the final code.
When you have an OpenAPI or Swagger spec for your service, bring it into the conversation early. A structured contract often produces the strongest drafts because it pins down paths, parameters, request bodies, and expected responses, which reduces guesswork compared with plain language or telemetry alone. The mode documentation describes how to attach, paste, or link a spec in Write a new test and how to enrich discovery results in Enrich with an OpenAPI spec.
To understand where this mode helps most, complete these steps.
Open Use k6 Script Authoring mode and read the descriptions of the three workflows. The documentation covers Write a new test, Discover and generate, and Work with an existing script.
Match each workflow to a real situation. Use the following mapping.
- Use Write a new test when you only have a test goal in plain language. This path uses QuickPizza so you can follow the same URL and checks in every milestone.
- Use Discover and generate when you have a service name and telemetry from your Grafana Cloud stack (metrics, logs, traces). Skip or shorten that milestone if you only want the QuickPizza track.
- Use Write a new test or Discover and generate with an OpenAPI or Swagger spec when you have a service contract. Combine the spec with plain-language goals or with telemetry-backed endpoint lists so generated output includes checks and payloads with less placeholder
// TODO:work. Refer to Use k6 Script Authoring mode and Enrich with an OpenAPI spec. - Use Write a new test or Discover and generate with a GitHub repository URL when source code is the best starting point (for example, the service is not in production yet or does not send telemetry to this stack). Refer to Add a GitHub repository as context in the mode documentation.
- Use Work with an existing script when you already have script code or artifacts to convert or improve.
Set your expectations for generated output using the following guidelines.
- Treat generated code as a draft you validate in the Grafana Cloud k6 script editor, locally with
k6 run, or both, and in review. - Keep ownership of pass/fail logic, thresholds, and CI behavior in version control.
- When you have an OpenAPI or Swagger spec, supply it with your prompts or discovery follow-ups. Specs are one of the strongest inputs for accurate k6 output because they constrain parameters, bodies, and checks. Refer to Use k6 Script Authoring mode and Enrich with an OpenAPI spec.
- Treat generated code as a draft you validate in the Grafana Cloud k6 script editor, locally with
You now have the workflow map for Script Authoring mode. In the next milestone, you generate a k6 script from a plain-language prompt against QuickPizza.