Use the script editor
The script editor is an integrated code editor available within Grafana Cloud k6, providing users with the convenience of writing scripts without the need to install applications on their local machines.
While many users run cloud tests from the CLI with their preferred IDE, varying organizational security rules may restrict some users from installing applications without a security team review.
The script editor supports almost all features of k6, no local machine required.
Create script
To create a new script using the script editor, follow these steps:
- Open the k6 app in your Grafana instance.
- Select Projects.
- Create a new project, or choose an existing one.
- Click Create new test.
- Under Script Editor, select Start Scripting.
The script editor comes with a pre-configured example script that you can either edit manually or use the following options:
- Script examples: Choose from various included scripts to learn how to handle authentication, submit forms, or use different protocols.
- Import HAR: Import a HAR file, overwriting your existing script in the script editor.
- Record a scenario: Use the browser recorder to create your script.
Once you’re done creating your script, select Create to save your script, or Create and Run to save and run your test.
Script editor features
The script editor has some built-in features to make it easier to write scripts.
Validation/error checking
If your script has a syntax error, the editor will alert you and prevent the script from running. Validation errors are displayed in the UI as:
There are validation errors, please fix them in order to run the test
Code Folding
Simplify reading and navigating your code by folding blocks of code using the down arrow next to the line numbers.
Variable highlighting
When you select a variable, the editor highlights other references to that variable in the script.
Limitations
The script editor can access all built-in k6 modules and remote modules.
However, if you need to import a custom library or file for parameterization, you must trigger your test using the CLI instead.