Skip to content

Commit 506a5c7

Browse files
chore(examples): refactor custom metrics example to include test steps (#2249)
1 parent a4feb0d commit 506a5c7

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

examples/browser-load-testing-playwright/flows.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,26 @@ async function checkPage(page, userContext, events) {
3636
await page.reload();
3737
}
3838

39-
async function multistepWithCustomMetrics(page, userContext, events) {
40-
// Part 1 of our flow
41-
await page.goto('https://www.artillery.io');
39+
async function multistepWithCustomMetrics(page, userContext, events, test) {
40+
//1. we get the convenience step() helper from the test object.
41+
//More information: https://www.artillery.io/docs/reference/engines/playwright#teststep-argument
42+
const { step } = test;
4243

43-
// Part 2 of our flow - we want to capture response times for this
44-
// part separately and report it as a custom metric:
44+
//2. We can now wrap parts of our Playwright script in step() calls
45+
await step('go_to_artillery_io', async () => {
46+
await page.goto('https://www.artillery.io');
47+
});
4548

46-
// First we record the current time:
47-
const startedTime = Date.now();
48-
// Our test then proceeds with the sequence of actions that we want to
49-
// report for specifically.
50-
//
51-
// NOTE: We only have one action here, but we could have a longer sequence of
52-
// actions here which would add up to the time we are tracking as
53-
// time_taken_for_part_of_flow metric.
54-
await page.goto('https://www.artillery.io/cloud');
55-
// We then calculate the amount of time previous actions took and use
56-
// Artillery's custom metrics API to record it. The metric will be available
57-
// in Artillery's report alongside other metrics.
58-
// For more information on custom metrics API please see:
59-
// https://www.artillery.io/docs/guides/guides/extension-apis#tracking-custom-metrics
60-
const difference = Date.now() - startedTime;
61-
events.emit('histogram', 'time_taken_for_part_of_flow', difference);
49+
await step('go_to_cloud_page', async () => {
50+
await page.goto('https://www.artillery.io/cloud');
51+
});
6252

63-
// Part 3 of our flow:
64-
await page.goto('https://www.artillery.io/docs');
53+
await step('go_to_docs', async () => {
54+
await page.goto('https://www.artillery.io/docs');
55+
});
56+
57+
// 3. latency metrics will be emitted automatically throughout the test for each step.
58+
// For more information on custom metrics, please see: https://www.artillery.io/docs/guides/guides/extension-apis#tracking-custom-metrics
6559
}
6660

6761
module.exports = {

packages/types/test/examples.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const exampleTestScripts = [
1818
'examples/artillery-engine-example/example.yaml',
1919
'examples/artillery-plugin-hello-world/test.yml',
2020
'examples/automated-checks/load-test-with-automated-checks.yml',
21-
'examples/browser-load-testing-playwright/advanced-custom-metric-for-subflow.yml',
2221
'examples/browser-load-testing-playwright/browser-load-test.yml',
2322
'examples/browser-load-testing-playwright/browser-smoke-test.yml',
23+
'examples/browser-load-testing-playwright/browser-test-with-steps.yml',
2424
'examples/cicd/aws-codebuild/tests/performance/socket-io.yml',
2525
'examples/cicd/github-actions/.github/workflows/load-test.yml',
2626
'examples/file-uploads/file-uploads.yml',

0 commit comments

Comments
 (0)