Measure

A measurement tool for browser-based metrics, handling various aspects of metric collection including navigation, video recording, and data collection.

Classes

Measure

Methods

add(name, value)

Adds a custom metric to the current measurement result. This method should be called after a measurement has started and before it has stopped.
Parameters:
NameTypeDescription
namestringThe name of the metric.
value*The value of the metric.
Throws:
Throws an error if called before a measurement cycle has started.
Type
Error

addObject(object)

Adds multiple custom metrics to the current measurement result. This method accepts an object containing multiple key-value pairs representing different metrics. Similar to `add`, it should be used within an active measurement cycle.
Parameters:
NameTypeDescription
objectObjectAn object containing key-value pairs of metrics to add.
Throws:
Throws an error if called before a measurement cycle has started.
Type
Error

(async) start(urlOrAlias, optionalAliasopt) → {Promise.<void>}

Starts the measurement process for a given URL or an alias. It supports starting measurements by either directly providing a URL or using an alias. If a URL is provided, it navigates to that URL and performs the measurement. If an alias is provided, or no URL is available, it sets up the environment for a user-driven navigation.
Parameters:
NameTypeAttributesDescription
urlOrAliasstringThe URL to navigate to, or an alias representing the test.
optionalAliasstring<optional>
An optional alias that can be used if the first parameter is a URL.
Throws:
Throws an error if navigation fails or if there are issues in the setup process.
Type
Error
Returns:
A promise that resolves when the start process is complete, or rejects if there are errors.
Type: 
Promise.<void>
Example
await commands.measure.start('https://www.example.org');
// Or start the measurement and click on a link
await commands.measure.start();
await commands.click.byLinkTextAndWait('Documentation');
// Remember to stop the measurements if you do not provide a URL
await commands.measure.stop();

(async) stop(testedStartUrl) → {Promise}

Stops the measurement process, collects metrics, and handles any post-measurement tasks. It finalizes the URL being tested, manages any URL-specific metadata, stops any ongoing video recordings, and initiates the data collection process.
Parameters:
NameTypeDescription
testedStartUrlstringThe URL that was initially tested. If not provided, it will be obtained from the browser.
Throws:
Throws an error if there are issues in stopping the measurement or collecting data.
Type
Error
Returns:
A promise that resolves with the collected metrics data.
Type: 
Promise

(async) stopAsError(errorMessage) → {Promise}

Stop the current measurement and mark it as a failure. This stop function will not measure anything on a page. This is useful if you need to stop a measurement in a (try) catch and you know something has failed.
Parameters:
NameTypeDescription
errorMessagestringThe message about the error. This will end up on the HTML report for sitespeed.io so give it a good message so you know what's gone wrong.
Since
  • 21.2.0
Returns:
A promise that resolves when the stop process has completed.
Type: 
Promise