From 586827aaaa692913f705a0027ea2074953d29086 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Wed, 14 Feb 2024 08:28:54 +0100 Subject: [PATCH] Example on how to handle an error --- .../scripting/tutorial-07-Debugging-Scripts.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/documentation/sitespeed.io/scripting/tutorial-07-Debugging-Scripts.html b/docs/documentation/sitespeed.io/scripting/tutorial-07-Debugging-Scripts.html index bf7865f43..bdf5d3eaf 100644 --- a/docs/documentation/sitespeed.io/scripting/tutorial-07-Debugging-Scripts.html +++ b/docs/documentation/sitespeed.io/scripting/tutorial-07-Debugging-Scripts.html @@ -30,4 +30,19 @@ export default async function (context, commands) { await commands.screenshot.take('myError'); } } +

If you measure a navigation by clicking on an element and the element do not exists or somnething goes wrong, you can stop the measuerement and make sure no metrics is collected.

/**
+ * @param {import('browsertime').BrowsertimeContext} context
+ * @param {import('browsertime').BrowsertimeCommands} commands
+ */
+export default async function (context, commands) {
+  
+  await commands.measure.start('my_trip');
+  try {
+    // do something that can break
+    await commands.mouse.singleClick.byLinkTextAndWait('Next page');
+    await commands.measure.stop();
+  } catch(error) {
+    await commands.measure.stopAsError('Could not click the next page link');
+  }
+ }
 
\ No newline at end of file