fakeData API
Fake Data offers a set of helpful methods under fakeData
object that you can use to take advantage of Fake Data's internal features.
Please not that some methods may work only in some execution contexts (background page, foreground page, and sandboxed iframe), and the return values may differ between them. Please check each method return value to see more details about this.
getGeneratorValue
- Details:
- Generate a random value from a specified generator.
- Arguments:
generator name
- The name of the generator that will be used. Can be a Default Generator or a Custom Generator.
- Returns:
- Will return a
Promise
that resolves to a string
containing the generated value
Context | Actual return value |
---|
(MV2) Background page | Promise which resolves to a string |
(MV2) Foreground page | Promise which resolves to a string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
return fakeData.getGeneratorValue('first_name');
getLastGeneratedValue
- Details:
- Retrieves the last generated value for a specific generator.
- Arguments:
generator name
- The name of the generator that will be used. Can be a Default Generator or a Custom Generator.
- Returns:
- Will return a
Promise
that resolves to a string
containing the retrieved value
Context | Actual return value |
---|
(MV2) Background page | Promise which resolves to a string |
(MV2) Foreground page | Promise which resolves to a string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
return fakeData.getLastGeneratedValue('first_name');
getFakeValue
- Details:
- Generate a random value based on the provided field name.
- Arguments:
field name
- The name of the field for which Fake Data will generate the value (similar to id
or name
attribute on an input element).
- Returns:
- Will return a
Promise
that resolves to a string
containing the generated value
Context | Actual return value |
---|
(MV2) Background page | Promise which resolves to a string |
(MV2) Foreground page | Promise which resolves to a string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
return fakeData.getFakeValue('i_want_a_full_name');
fillElement
- Details:
- Fills an input element from page
- Arguments:
element
- The DOM element from page that should be filled
- Returns
- Will return a
Promise
that resolves to a string
containing the generated value
Context | Actual return value |
---|
(MV2) Foreground page | Promise which resolves to a string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
fakeData.fillElement(document.querySelector('input'));
getGeneratorMatchForElement
- Details:
- Get the matching generator name for a DOM element
- Arguments:
element
- The DOM element from page
- Returns
- Will return a
Promise
that resolves to a string
containing the generator name
Context | Actual return value |
---|
(MV2) Foreground page | Promise which resolves to a string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
return fakeData.getGeneratorMatchForElement(document.querySelector('input'));
getUniqueSelector
- Details:
- Get the a unique selector string for a DOM element
- Arguments:
element
- The DOM element from page
- Returns
- Will return
string
containing the selector. Can also return a Promise
that resolves to a string
depending on the context on which is called - See the table below.
Context | Actual return value |
---|
(MV2) Foreground page | string |
(MV3) Sandbox iframe | Promise which resolves to a string |
Public API Custom Integration | Promise which resolves to a string |
return fakeData.getUniqueSelector(document.querySelector('input'));
- Details:
- Trigger a DOM event on a DOM element
- Arguments:
element
- The DOM element from pageevent name
- The DOM event that will be triggered on the element
- Returns
- Will
true
on success. Can also return a Promise
which resolves to value true
depending on the context on which is called - See the table below.
Context | Actual return value |
---|
(MV2) Foreground page | boolean |
(MV3) Sandbox iframe | Promise which resolves to a boolean |
Public API Custom Integration | Promise which resolves to a boolean |
fakeData.triggerInputChangeEvent(document.querySelector('button'), 'click');
getFillSessionId
- Details:
- Retrieves the current fill session id.
- Fill session ids are unique identifiers that change every time you fill an element, a form, or the entire page. When filling multiple elements at once (like an entire form or an entire page), the session id will be the same for all inputs.
- Arguments:
- Returns:
- Will return a value containing a unique identifier for the fill session
Context | Actual return value |
---|
(MV2) Background page | string value |
(MV2) Foreground page | int value |
(MV3) Sandbox iframe | Promise which resolves to a string |
return fakeData.getFillSessionId();
getFillSessionType
- Details:
- Retrieves the type of the current fill session
- Arguments:
fill_session_id
(optional) - A previous fill session id (will use the current session id if empty)
- Returns:
- Will return a
string
containing the filled session type
Context | Actual return value |
---|
(MV2) Background page | string value |
Possible return values:
- single
- form
- page
- multiple-fields
- preview
Usage:
return fakeData.getFillSessionType();
getDatasetValue
Pro only
- Details:
- Retrieves a random value from a Dataset column.
- Arguments:
dataset name
- The exact name of the datasetdataset column
- The exact column name from the dataset
- Returns:
- Will return a
string
containing a random value from the requested column in the requested dataset
Context | Actual return value |
---|
(MV2) Background page | string value |
(MV3) Sandbox iframe | string value |
return fakeData.getDatasetValue('test dataset', 'First Name');