Scripting and tests Pro / Enterprise
The scripting feature allows you to run custom JavaScript inside Kreya. Among other things, it allows you to create tests and view the results of them.
Kreya operation scripts
Kreya operation scripts are attached directly to a specific Kreya operation and run automatically when the operation is invoked. These can mainly be used to test operation responses.
Find more information about Kreya operation scripts in the Operation scripts documentation.
Kreya scripts
Kreya scripts are scripts within Kreya that provide more advanced control, allowing you to programmatically invoke one or more operations using logic like loops and conditional statements for complex workflows or test scenarios.
Find more information about Kreya scripts in the Scripts documentation.
Script APIs
Kreya offers a set of useful APIs. Checkout the operation script API reference and scripts API reference documentation as well as the general script API reference. You can also share code or import external NPM modules.
User variables
User variables are a project-scoped key/value store that lets you carry state between
operations, scripts, collections and templating. Set them from scripts via
kreya.variables and reference
them via {{ vars.my_var }} in templating:
// In some script
kreya.variables.set('my_var', 123);
// In some other script
const myVar = kreya.variables.get('my_var');
// Or via templating in an operation
{{ vars.my_var }}
See the dedicated User variables page for the full API, valid keys, scope and persistence details.
Faker
Similar to using faker in templating, it can be used with kreya.faker.
It uses Bogus behind the scenes. As an example, you could use
const name = kreya.faker.name.fullName();
to generate a fake, but realistic full name. See Generating fake data for the available categories and for generating numbers, GUIDs and dates with custom formats and ranges.
Tests
Kreya supports defining tests in scripts using the kreya.test function.
Test results are displayed in the Tests tab, showing the number of passed and failed tests.
For detailed examples and instructions, see the tests documentation.
Previewing data
Kreya's preview capabilities allow you to visualize data directly within the app.
Using the kreya.preview API, you can render PDFs, HTML, or custom visualizations to transform raw response data into meaningful insights.
For more details and examples, see the Previewing Data documentation.