Skip to main content

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

Sometimes, you may need to share data between different operations. For example, if you have a process where you create an entity → update the entity → delete the entity, changing the entity ID manually each time becomes annoying. It would be much easier if you could temporarily store the ID of the created entity and reference it from the other two operations. For such use cases, user variables are the way to go.

The feature is available through the kreya.variables object. User variables can also be referenced via templating. A common use case is to set a variable in an operation script and then referencing it from somewhere else:

// 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 }}

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.

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.