Recording custom values to use when replaying user sessions

In some situations, you may want to record custom values to use when replaying user sessions. This is typically not needed, but can be useful in some cases for instance if:

  • Meticulous is being served static content when running tests, but your server would normally inject some dynamic values into the page.
  • You've overridden the default behaviour and configured Meticulous to log in as a single user, but you need to record some user-specific values to replay the session as a different user.

How can I record values?

During recording of a user session, you can record custom values using the methods on the window.Meticulous.record object:

  • For object values: Call recordCustomData(key, value). If the value is already present, it will be overwritten.
  • For array values: Call pushToCustomDataArray(arrayId, valueToAppend). If the array is not already present, it will be created. The new value will be appended to the array.

Note that both these methods take only strings as keys or values, so if you need to record a complex object you'll need to serialize it to a string. For instance you could do:

window.Meticulous?.record?.recordCustomData(
  "preRenderedData",
  JSON.stringify(window.PRE_RENDERED_DATA)
);

For further information, consult the code.

How can I use the recorded values?

When Meticulous is running tests, you can access the recorded values in your code by using the methods on the window.Meticulous.replay object:

  • For object values: Call retrieveCustomData(key). This will return null if the key is not found.
  • For array values: Call retrieveCustomDataArray(arrayId). This will return an empty array if the array is not found.

For instance, you could do:

const preRenderedData = window.Meticulous?.replay?.retrieveCustomData("preRenderedData");
if (preRenderedData) {
  window.PRE_RENDERED_DATA = JSON.parse(preRenderedData);
}

For object values, you can also inject these into request headers in the Custom Request Headers section of the project settings.

TypeScript Types

For TypeScript type definitions for the window.Meticulous object, see TypeScript Types for window.Meticulous.

Where can I reach out for support?

Reach out to eng@meticulous.ai and we'll be happy to help.