artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
8.04k stars 511 forks source link

Playwright output as HAR file #2197

Closed roydekleijn closed 1 year ago

roydekleijn commented 1 year ago

Hello,

I'm running some Playwright flows with artillery. I try to save the output (requests made by the browser) into a HAR file. This is fine when running 1 session/arrival/vusers, but doesn't work when running multiple sessions/arrivals.

This is the Playwright config I'm using:

  engines:
    playwright:
      contextOptions:
        recordHar: 
          path: 'requests3.har'
          mode: 'full'
          urlFilter: '**/xas/**'
      launchOptions:
        headless: true

My question is, how can I combine all the output in a single HAR file, OR how can I create 1 HAR file per session/arrival/vusers ? Which then can be processed later on.

Happy to collaborate on this! Roy

hassy commented 1 year ago

hi @roydekleijn 👋 - I'd have to check but it may not be working because Artillery creates a separate browser for each virtual user, and each of those browsers is trying to write to the same file. Is there a particular reason you want to save requests from all VUs?

roydekleijn commented 1 year ago

Hello, Thanks! If I'm right, it's more of an issue for the Playwright-team then?

Can we somehow manage that a separate file is created per Vuser?

I will describe my use case a bit more,

hassy commented 1 year ago

Thanks for the details @roydekleijn. If I understand correctly you need the HAR files to get performance metrics for the API routes that are triggered by actions performed by the Playwright script? That's possibly something we could implement natively in our integration and provide those metrics alongside other metrics reported by Artillery.

In the meantime, I think you can use the routeFromHAR to record separate HAR file for each VU.

First make sure that your Playwright test function is passed the userContext argument from Artillery, e.g.:

async function myPlaywrightTestFunction(page, userContext) {
}

And then add this as the first line of your Playwright test function:

  await page.routeFromHAR(`/tmp/playwright-har-${userContext.vars.$uuid}.har`, {
    update: true
  });

This makes use of the unique $uuid variable set for each VU by Artillery to name each HAR file.

This should produces a bunch of HAR files looking like this:

CleanShot 2023-10-10 at 12 37 26

roydekleijn commented 1 year ago

Awesome, this is what I was looking for.

I will create a small utility to process the files and report the timings, Thanks!

It would be awesome is this will become part of Artillery!

hassy commented 1 year ago

Great, glad that's what you were looking for! and thanks for the idea :)