Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions for random data generation #3720

Open
AntonShuvaev opened this issue Feb 9, 2025 · 3 comments
Open

Functions for random data generation #3720

AntonShuvaev opened this issue Feb 9, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@AntonShuvaev
Copy link

Problem to solve

I want to be able to use random data in requests like first name, last name, email, etc. Currently, we're limited to only newUuid and newDate functions.

Proposal

It would be great to have more random data generation functions besides existing newUuid and newDate. As an example, Postman has a great set of dynamic variables powered by faker.js (see docs: https://learning.postman.com/docs/tests-and-scripts/write-scripts/variables-list/). The fake-rs library (https://github.com/cksac/fake-rs) could be used for implementation.

I think it would be convenient to prefix such functions with $ to separate them from usual variables, as this is common in many API clients. For some functions, it would be even better to support arguments (e.g., $randomInt(123), $randomAlphaNumeric(10)). Or even support expressions so we can do things like this {{$randomFirstName + ' ' + $randomLastName}}

@AntonShuvaev AntonShuvaev added the enhancement New feature or request label Feb 9, 2025
@jruot
Copy link

jruot commented Feb 21, 2025

I'm having a similar problem. For example, I would like to pick a random value from a pre-defined list, such as a country code. It would also be good to define the date format for the newDate function.

@SilenLoc
Copy link

SilenLoc commented Mar 6, 2025

I would like to have it too but with a simple generation of random combinations of chars by sampling a vector:

{{randomChar(["2,A,4,e"],5)}}

would generate for example:

A22Ae

@techfg
Copy link

techfg commented Mar 28, 2025

Having something like this would be extremely helpful. The existing newUuid and newDate are helpful but for fields that only accept certain characters, they often cannot be used when random/unique data is required.

The only solutions currently that I'm aware of are variables, variable-file, environment variables but these two are extremely limiting and add a dependency or CLI argument when you simply want to run a single file ad-hoc. The test itself should be capable of generating the dynamic data required.

As a starting point, having functions that generate a random set of letters, set of digits, etc. would be helpful, even adding a newEpoch/newTimestamp would give an easy way to get digits only. The approach postman takes for built-ins as @AntonShuvaev mentions would work well. As a starting point, some basic functions like randomAlphaNumeric, randomInt would solve a lot of the use cases I would suspect.

Ideally, there would be a way to define/provide hurl with a custom function that would allow all uses cases to be covered. For example, I could provide hurl a "randomUsername" function and when hurl sees {{randomUsername}} the function would be called. This approach, while ideal, would be more difficult to implement I suspect but it would meet all use cases without having to wait for hurl to add new built-in functions.

Appreciate the consideration!

Related #606

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants