Open jordan-angold-sophos opened 1 year ago
Note that the log shows a hint:
[2023-08-18 20:32:35] ERROR: [browsertime.command.measure] You need to have done one (start/stop) measurement before you can add any metrics to a result.
This error seems to be in reference to first_stopwatch
.
The first_stopwatch
metric is not recorded in any output json files. The second_stopwatch
metric incorrectly appears in the output json files for https://google.com, the URL used in first_test
.
I think this is due to https://github.com/sitespeedio/browsertime/blob/main/lib/core/engine/command/measure.js#L327 . When adding a metric, the index used is this.numberOfMeasuredPages - 1
, but start() and stop() index at this.numberOfMeasuredPages
.
The doc language on StopWatch.stopAndAdd() says that the measurement will be added to the "last measured page", which suggests that this could conceivably be intentional behaviour -- but if it is, then it makes stopwatches awkward to use.
The stop watch is always registered to the last measured URL, so to make it work you need to adjust the script to first measure that first page load and then do the stop watch thing.
Are you saying that the correct version of the script is not:
await commands.navigate("https://sitespeed.io");
await commands.measure.start("first_test");
const stopWatch = commands.stopWatch.get('first_stopwatch');
// some interesting operation here
const stopWatchTime = stopWatch.stopAndAdd();
return commands.measure.stop();
but instead:
await commands.navigate("https://sitespeed.io");
await commands.measure.start("first_test");
const stopWatch = commands.stopWatch.get('first_stopwatch');
// some interesting operation here
const stopWatchTime = stopWatch.stop();
await commands.measure.stop();
await commands.measure.add(stopWatch.name, stopWatchTime);
because that makes StopWatch.stopAndAdd()
fairly worthless, and makes the whole test more verbose and awkward to write.
Have you read the documentation?
URL
https://sitespeed.io
What are you trying to accomplish
I'm testing an SPA and trying to record several test cases, each of which has custom timers using a stopwatch. I am trying to automate extracting those custom timers from JSON data retrieved using the
analysisstorer
plugin.What browser did you use?
Chrome
How to reproduce
Log output