Capture response time

Hi @Gerard,

For now, the best way for you to time a click followed by a navigation to another page, is to use Date.now(). You can create a custom metric for this measurement which will be printed out in the summary at the end of the test run.

Here’s a code snippet of how it might look:

import { Trend } from 'k6/metrics';
...
const clickNavTrend = new Trend('click_nav');
...
  var start;
  var end;
...
    start = Date.now();
    return Promise.all([
      page.waitForNavigation(),
      page.locator('input[type="submit"]').click(),
    ]);
  }).then(() => {
    end = Date.now();
    const diff = end - start;
    clickNavTrend.add(diff);

At the end you should see something like:

click_nav........................: avg=395.8    min=374      med=398     max=407      p(90)=404.3    p(95)=405.65

Hope that helps.

Cheers,
Ankur

3 Likes