@@ -36,32 +36,26 @@ async function checkPage(page, userContext, events) {
36
36
await page . reload ( ) ;
37
37
}
38
38
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 ;
42
43
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
+ } ) ;
45
48
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
+ } ) ;
62
52
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
65
59
}
66
60
67
61
module . exports = {
0 commit comments