Skip to Content
·

fake-data - Use realistic fake data

This plugin allows you to use realistic fake data in your Artillery tests easily, by giving you access to most functions in the Faker  library.

  • Please check the Faker API documentation  for available functions;
  • Functions are exposed with flattened names: faker.<module>.<function>() becomes $<moduleFunction>(). For example, faker.internet.email() is available as $internetEmail(), and faker.person.fullName() as $personFullName();
  • The functions are available to use as $<functionName> in your YAML script (e.g. $colorHuman());
  • You can customise a function’s behaviour by passing a configuration object to the plugin (equal to the options argument of the Faker function).

Known limitations

  • This plugin is only compatible with the http engine
  • This plugin is not compatible with before/after hooks
  • Only Faker functions that accept at most one argument (an options object) are supported;
  • If using the function in a hook, you still need to pass the configuration object through the plugin configuration.
  • If using the function in a hook, you will only be able to use it with beforeRequest, afterResponse and function.

Usage

Basic Usage

First, enable the plugin in your Artillery config file.

config: plugins: fake-data: {}

Then, the functions will be available to use in your YAML script.

scenarios: - name: 'Test with fake data' flow: - post: url: '/user' json: name: '{{ $personFullName() }}' email: '{{ $internetEmail() }}' password: '{{ $internetPassword() }}'

Configuring specific functions

You can pass a configuration object to the plugin to customize the behavior of the specific functions. For example:

config: plugins: fake-data: internetPassword: length: 5

The above config will make the $internetPassword() function generate passwords with 5 characters.

Usage with hooks

You can also use the functions in javascript hooks. They will be available under context.funcs. For example:

function myBeforeRequestHook(req, context, ee, next) { context.vars.password = context.funcs.$internetPassword(); next(); }

Please note that:

  • The function will only be available in the beforeRequest, afterResponse and function hooks.
  • You still need to pass the configuration object through the plugin configuration.

Migrating from falso

Earlier versions of this plugin used the falso  library. The plugin now uses Faker  instead since Artillery v2.0.33.

The most commonly used falso-style function names continue to work as deprecated aliases and will be removed in a future release. A deprecation warning is logged when they are used. Update your scripts to use the Faker function names:

Deprecated (falso)Use instead (Faker)
$randEmail$internetEmail
$randFullName$personFullName
$randFirstName$personFirstName
$randLastName$personLastName
$randUserName$internetUsername
$randPassword$internetPassword
$randUuid$stringUuid
$randPhoneNumber$phoneNumber
$randCity$locationCity
$randCountry$locationCountry
$randStreetAddress$locationStreetAddress
$randZipCode$locationZipCode
$randCompanyName$companyName
$randNumber$numberInt
$randBoolean$datatypeBoolean
$randUrl$internetUrl
$randIp$internetIpv4
$randWord$loremWord
$randSentence$loremSentence
$randParagraph$loremParagraph
$randText$loremText
$randJobTitle$personJobTitle
$randColor$colorHuman
$randProductName$commerceProductName

Function options have changed

Per-function configuration objects now use Faker’s option shapes, under the Faker function name. For example, falso’s randPassword: { size: 5 } becomes internetPassword: { length: 5 }. Deprecated aliases do not translate old falso options - move your configuration to the Faker function name and option shape.

Other falso function names that are not listed above are no longer available. Find the equivalent function in the Faker API documentation  and use its flattened name.

Last updated on