1.9.0 • Published 17 hours ago

artillery-engine-playwright v1.9.0

Weekly downloads
-
License
MPL-2.0
Repository
-
Last release
17 hours ago

artillery-engine-playwright


Ever wished you could run load tests with real browsers? Well, now you can.

This Artillery engine lets you combine Playwright with Artillery to be able to launch a whole lot of real browsers to do full browser load testing.

At a glance

  • 🤖   Run load tests with real (headless) Chrome instances
  • 🛰   Run synthetic checks in CICD with the same Artillery + Playwright scripts
  • 📊   See most important front-end metrics (Largest Contentful Paint (LCP), First Contentful Paint (FCP) etc) and how they are affected by high load
  • ♻️    Use Playwright for load testing (full access to page API)
  • 🏎   Create new load testing scripts 10x faster with playwright codegen
  • 🌐   Launch thousands of browsers, with zero infrastructure setup with Artillery Pro

Perfect for testing complex web apps

Read the official launch blog post here: Launching 10,000 browsers for fun and profit

Why load test with browsers?

Load testing complex web apps can be time consuming, cumbersome, and brittle compared to load testing pure APIs and backend services. The main reason is that testing web apps requires a different level of abstraction: whereas APIs work at endpoint level, when testing web apps a page is a much more useful abstraction.

Summarized in the table below:

APIs & microservicesWeb apps
Abstraction levelHTTP endpointWhole page
Surface areaSmall, a handful of endpointsLarge, calls many APIs. Different APIs may be called depending on in-page actions by the user
Formal specUsually available (e.g. as an OpenAPI spec)No formal specs for APIs used and their dependencies. You have to spend time in Dev Tools to track down all API calls
In-page JSIgnored. Calls made by in-page JS have to be accounted for manually and emulatedRuns as expected, e.g. making calls to more HTTP endpoints

All of those factors combined make load testing web apps with traditional approaches very frustrating and time consuming. 😞

Usage ⌨️

Installation

Install Artillery and this engine:

npm install -g artillery artillery-engine-playwright

(See Use in Docker/CI if running tests in Docker/CI)

Running a test

Create an Artillery script:

hello-world.yml:

config:
  target: https://www.artillery.io
  # Enable the Playwright engine:
  engines:
    playwright: {}
  processor: "./flows.js"
scenarios:
  - engine: playwright
    flowFunction: "helloFlow"
    flow: []

Use a Playwright script to describe virtual user scenario:

(Note: this script was generated with playwright codegen. page is an instance of Playwright page.)

flows.js:

module.exports = { helloFlow };

async function helloFlow(page) {
  //
  // The code below is just a standard Playwright script:
  //
  // Go to https://artillery.io/
  await page.goto('https://artillery.io/');
  // Click text=Pricing
  await page.click('text=Pricing');
  // assert.equal(page.url(), 'https://artillery.io/pro/');
  // Click text=Sign up
  await page.click('text=Sign up');
}

Run it:

artillery run hello-world.yml

Artillery runs Playwright-based scenarios, and provides user-centric metrics that measure perceived load speed such as LCP and FCP:

--------------------------------
Summary report @ 11:24:53(+0100)
--------------------------------

vusers.created_by_name.Dev account signup: .................. 1
vusers.created.total: ....................................... 1
vusers.completed: ........................................... 1
vusers.session_length:
  min: ...................................................... 5911.7
  max: ...................................................... 5911.7
  median: ................................................... 5944.6
  p95: ...................................................... 5944.6
  p99: ...................................................... 5944.6
browser.page.domcontentloaded: .............................. 2
browser.page.domcontentloaded.https://artillery.io/: ........ 1
browser.page.domcontentloaded.https://artillery.io/pro/: .... 1
browser.page.FCP.https://artillery.io/:
  min: ...................................................... 1521.1
  max: ...................................................... 1521.1
  median: ................................................... 1525.7
  p95: ...................................................... 1525.7
  p99: ...................................................... 1525.7
browser.page.dominteractive:
  min: ...................................................... 162
  max: ...................................................... 1525
  median: ................................................... 162.4
  p95: ...................................................... 162.4
  p99: ...................................................... 162.4
browser.page.dominteractive.https://artillery.io/:
  min: ...................................................... 1525
  max: ...................................................... 1525
  median: ................................................... 1525.7
  p95: ...................................................... 1525.7
  p99: ...................................................... 1525.7
browser.page.LCP.https://artillery.io/:
  min: ...................................................... 1521.1
  max: ...................................................... 1521.1
  median: ................................................... 1525.7
  p95: ...................................................... 1525.7
  p99: ...................................................... 1525.7
browser.page.dominteractive.https://artillery.io/pro/:
  min: ...................................................... 162
  max: ...................................................... 162
  median: ................................................... 162.4
  p95: ...................................................... 162.4
  p99: ...................................................... 162.4
browser.page.FCP.https://artillery.io/pro/:
  min: ...................................................... 205.3
  max: ...................................................... 205.3
  median: ................................................... 206.5
  p95: ...................................................... 206.5
  p99: ...................................................... 206.5
browser.page.LCP.https://artillery.io/pro/:
  min: ...................................................... 205.3
  max: ...................................................... 205.3
  median: ................................................... 206.5
  p95: ...................................................... 206.5
  p99: ...................................................... 206.5

Configuration

The underlying Playwright instance may be configured through config.engines.playwright.

You can pass the following options in:

Example 1: turn off headless mode

You can turn off the default headless mode to see the browser window for local debugging by setting the headless option.

config:
  engines:
    playwright:
      launchOptions:
        headless: false

Example 2: set extra HTTP headers

This example sets the extraHTTPHeaders option for the browser context that is created by the engine.

config:
  engines:
    playwright:
      contextOptions:
        extraHTTPHeaders:
          x-my-header: my-value

Aggregate metrics by scenario name

By default metrics are aggregated separately for each unique URL. When load testing the same endpoint with different/randomized query params, it can be hepful to group metrics by a common name.

To enable the option pass aggregateByName: true to the playwright engine and give a name to your scenarios:

config:
  target: https://artillery.io
  engines:
    playwright: { aggregateByName: true } 
  processor: "./flows.js"
scenarios:
  - name: blog
    engine: playwright
    flowFunction: "helloFlow"
    flow: []

flows.js

module.exports = { helloFlow };

function helloFlow(page) {
  await page.goto(`https://artillery.io/blog/${getRandomSlug()}`);
}

This serves a similar purpose to the useOnlyRequestNames option from the metrics-by-endpoint artillery plugin.

Flow function API

By default, only the page argument (see Playwright's page API) is required for functions that implement Playwright scenarios, e.g.:

module.exports = { helloFlow };

async function helloFlow(page) {
  // Go to https://artillery.io/
  await page.goto('https://artillery.io/');
}

The functions also have access to virtual user context and events arguments, which can be used to access scenario variables for different virtual users, or to track custom metrics.

module.exports = { helloFlow };

async function helloFlow(page, vuContext, events) {
  // Increment custom counter:
  events.emit('counter', 'user.page_loads', 1);
  // Go to https://artillery.io/
  await page.goto('https://artillery.io/');
}

More examples

See Artillery + Playwright examples in the main artillery repo.

Use in Docker/CI

Use the Dockerfile which bundles Chrome, Playwright and Artillery to run your tests in CI.

Note: To keep the Docker image small, browsers other than Chromium are removed (the saving is ~500MB)

Performance (Does it scale?)

When you run load tests with browsers your main bottleneck is going to be memory. Memory usage is what will limit how many Chrome instances can run in parallel in each VM/container. (Remember that every virtual user (VUs) will run its own copy of Chrome - just like in the real world.)

Two factors will determine how many VUs will be able to run in parallel:

  1. Memory usage of the pages that the VU navigates to and uses. Lightweight pages will mean each VU uses less memory while it's running.
  2. How long each VU runs for - the longer each session, the more VUs will be running at the same time, the higher memory usage will be.

The engine tracks a browser.memory_used_mb metric which shows the distribution of memory usage across all pages in each scenario (in megabytes). The value is read from window.performance.memory.usedJSHeapSize API. The metric is recorded for every load event.

Ultimately, there is no formula to determine how many VUs can be supported on a given amount of memory unfortunately as it will depend on the application and VU scenario. The rule of thumb is to scale out horizontally and run with as much memory as possible and track VU session length and memory usage of Chrome to be able to tweak the number of containers/VMs running your tests.

Questions, comments, feedback?

➡️   Let us know via Artillery Discussion board


License 📃

MPL 2.0

1.9.0-07478c3

17 hours ago

1.9.0-198c0a7

3 days ago

1.9.0-b54a530

5 days ago

1.9.0-88a6cf1

6 days ago

1.8.0-129c69a

7 days ago

1.8.0-bf75e55

7 days ago

1.8.0-fedb959

7 days ago

1.8.0-0e34b80

7 days ago

1.8.0-5374048

7 days ago

1.9.0

7 days ago

1.8.0-fa6acff

7 days ago

1.8.0-2344d60

8 days ago

1.8.0-6680314

7 days ago

1.8.0-88e686a

7 days ago

1.8.0-addd21d

11 days ago

1.8.0-2a2f7a1

11 days ago

1.8.0-c0a74fe

12 days ago

1.8.0-99513b7

11 days ago

1.8.0-385f468

12 days ago

1.8.0-4d40d0b

14 days ago

1.8.0-02da550

17 days ago

1.8.0-e9feebe

18 days ago

1.8.0-d5dd8b4

18 days ago

1.8.0-b9d895b

19 days ago

1.8.0-af8834b

20 days ago

1.7.0-e3e1aa5

22 days ago

1.7.0-4b6546e

22 days ago

1.8.0

22 days ago

1.7.0-69471c7

25 days ago

1.7.0-7c09830

25 days ago

1.7.0-4206f30

25 days ago

1.6.0-732a76a

1 month ago

1.6.0-c99fd70

1 month ago

1.6.0-042221c

1 month ago

1.6.0-83ceb0d

1 month ago

1.6.0-af0720c

1 month ago

1.6.0-ead20b3

1 month ago

1.7.0

1 month ago

1.6.0-d55b152

2 months ago

1.6.0-db92535

2 months ago

1.6.0-9c6625c

2 months ago

1.6.0-fdd9363

2 months ago

1.6.0

2 months ago

1.5.0-f2922e9

2 months ago

1.5.0-a0dc4d3

2 months ago

1.5.0-48e284c

2 months ago

1.5.0-578c74a

2 months ago

1.5.0-46ff72e

2 months ago

1.5.0-1ed48b5

2 months ago

1.5.0-61a6b69

2 months ago

1.5.0-711584a

2 months ago

1.5.0-f0fd405

2 months ago

1.5.0-34bd561

2 months ago

1.5.0-30688df

2 months ago

1.5.0-5ebf998

2 months ago

1.5.0-11f0221

2 months ago

1.5.0-56d9180

2 months ago

1.5.0-2e563c1

2 months ago

1.5.0-ef2802b

2 months ago

1.5.0-3365696

2 months ago

1.5.0-9eb4de7

3 months ago

1.5.0-0c8e536

3 months ago

1.4.0-e22f369

3 months ago

1.5.0

3 months ago

1.4.0-185276e

3 months ago

1.4.0-339dd38

3 months ago

1.4.0-018c917

3 months ago

1.4.0-f9d7fcb

3 months ago

1.4.0-f6a6aa8

3 months ago

1.4.0-c2d53ba

3 months ago

1.4.0-f5cba1a

3 months ago

1.4.0-6e56af4

3 months ago

1.3.0-49f4602

3 months ago

1.3.0-e68006e

3 months ago

1.3.0-fde8a88

3 months ago

1.3.0-3f45ead

3 months ago

1.4.0

3 months ago

1.3.0-db4ca95

3 months ago

1.3.0-dab3448

3 months ago

1.3.0-e2435a9

3 months ago

1.3.0-c0bd9d8

3 months ago

1.3.0-347c371

3 months ago

1.3.0-edc94a9

3 months ago

1.3.0-8e81e34

3 months ago

1.3.0-0a139ea

3 months ago

1.2.0-981fcd0

4 months ago

1.2.0-5b07d5e

4 months ago

1.3.0

4 months ago

1.2.0-35f0e1c

4 months ago

1.2.0-5e061cf

4 months ago

1.2.0-e359bd2

4 months ago

1.2.0-a73a169

4 months ago

1.2.0-1b6220c

4 months ago

1.2.0-efe1a6e

4 months ago

1.2.0-cb320f9

4 months ago

1.2.0-d68482d

4 months ago

1.2.0-52b9e3b

4 months ago

1.2.0-c65efbc

4 months ago

1.2.0-d46133f

4 months ago

1.2.0-f9b94ff

4 months ago

1.2.0-a0b6328

4 months ago

1.2.0-d7109dd

4 months ago

1.2.0-1c936ad

4 months ago

1.2.0-e2eb716

4 months ago

1.2.0

4 months ago

1.1.0-049205b

4 months ago

1.1.0-0e7fadc

4 months ago

1.1.0-da20704

4 months ago

1.1.0-21c8e17

4 months ago

1.2.0-2c125ab

4 months ago

1.2.0-db60c0d

4 months ago

1.1.0-84b6b14

4 months ago

1.1.0-aaaf4d7

4 months ago

1.1.0-6fd477f

4 months ago

1.1.0-213bcb5

4 months ago

1.1.0-7f1d779

5 months ago

1.1.0-fb0b4c6

5 months ago

1.1.0-2531936

5 months ago

1.1.0-aec0b89

5 months ago

1.1.0-1091257

5 months ago

1.1.0-f98bb48

5 months ago

1.1.0-4ae406b

5 months ago

1.1.0-0f9e351

5 months ago

1.1.0-854765f

5 months ago

1.1.0-6103717

5 months ago

1.1.0-67408d1

5 months ago

1.1.0-29a4861

6 months ago

1.1.0-f0ed01e

6 months ago

1.1.0-99d295c

6 months ago

1.1.0-40f80cf

6 months ago

1.1.0-ec3de6a

6 months ago

1.1.0-d51d159

6 months ago

1.1.0-2894fc4

6 months ago

1.1.0-c163dc0

6 months ago

1.1.0-f449d5d

6 months ago

1.1.0-ad6a2e9

6 months ago

1.1.0-4d794e3

6 months ago

1.1.0-f7534a2

6 months ago

1.1.0-498fd09

6 months ago

1.1.0-a2602d2

6 months ago

1.1.0-ffdd0a1

6 months ago

1.1.0-b67bebb

6 months ago

1.1.0-486ce72

6 months ago

1.1.0-d69052f

6 months ago

1.1.0-6cef867

6 months ago

1.1.0-e8a69c3

6 months ago

0.3.1-338b070

9 months ago

0.3.2-9ac3e12

7 months ago

0.3.1-c34ae8a

9 months ago

1.0.0-fef0907

6 months ago

0.3.1-8771d37

10 months ago

0.3.2-9c51118

7 months ago

0.3.1-533da4b

9 months ago

0.3.1-47b5181

9 months ago

0.3.2-c6362a6

7 months ago

1.0.0-7631d27

7 months ago

0.3.1-eeee67c

9 months ago

0.3.1-b9eed29

9 months ago

0.3.2-b0f1e05

8 months ago

0.3.1-0a58dd8

9 months ago

1.0.0-3aa67ba

6 months ago

0.3.2-f8c884c

7 months ago

0.3.1-285d783

9 months ago

0.3.1-006b8d0

9 months ago

0.3.2-3a22187

7 months ago

1.0.0-d6a468b

6 months ago

1.0.0-cc9156a

7 months ago

0.3.2-38ff32c

7 months ago

1.0.0-a4defca

6 months ago

1.0.0-c117677

6 months ago

1.0.0-18ad4ac

6 months ago

0.3.2-b8419d2

8 months ago

0.3.2-ab48a8e

7 months ago

0.3.2-ab5dd4f

8 months ago

0.3.2-1eac5df

7 months ago

0.3.2-5b52b4d

7 months ago

1.0.0-15fcca7

6 months ago

0.3.2-4c01280

8 months ago

0.3.1-076314a

9 months ago

1.0.0-8ddaa8a

7 months ago

0.3.2

9 months ago

0.3.1-1859275

9 months ago

1.0.0-abc8122

7 months ago

1.0.0-563696c

6 months ago

0.3.2-ba9baf5

7 months ago

1.1.0

6 months ago

0.3.2-4af8d73

8 months ago

0.3.2-0467c8d

7 months ago

0.3.2-ed94c28

7 months ago

1.0.0-ef9d096

7 months ago

0.3.1-407d225

9 months ago

0.3.1-7085146

9 months ago

1.0.0-6a9c57c

6 months ago

1.0.0-9277f14

6 months ago

0.3.2-d39abda

8 months ago

1.0.0-18186a1

6 months ago

0.3.2-77ea3e9

7 months ago

1.0.0-766ce39

6 months ago

1.0.0-61d96f9

6 months ago

0.3.1-c613494

9 months ago

0.3.2-800b2a7

8 months ago

0.3.1-839736f

9 months ago

1.0.0-ee181c2

6 months ago

0.3.2-8697334

8 months ago

0.3.1-e07b755

10 months ago

0.3.1-c20229c

9 months ago

0.3.1-2f484f8

9 months ago

1.0.0-a4feb0d

7 months ago

0.3.2-8622de3

7 months ago

0.3.1-651351e

9 months ago

0.3.2-3f3e92d

8 months ago

0.3.2-2c714fc

8 months ago

1.0.0-6602d26

6 months ago

1.0.0

7 months ago

0.3.1-5b10fdf

9 months ago

0.3.1-4030f6d

9 months ago

1.1.0-ecfb4ff

6 months ago

0.3.2-a77a3e9

8 months ago

0.3.1-06989c6

9 months ago

1.1.0-cad8289

6 months ago

0.3.1-ecd59d7

9 months ago

0.3.2-6e08ffe

7 months ago

0.3.2-0bf63e9

8 months ago

0.3.2-683e569

7 months ago

0.3.1-f351294

9 months ago

0.3.1-144e77d

9 months ago

0.3.1-7c83e2b

9 months ago

1.0.0-12670e3

6 months ago

0.3.1-c6ee732

9 months ago

0.3.1-884a216

10 months ago

0.3.2-989328c

8 months ago

0.3.1-c08c695

10 months ago

1.0.0-84efa96

7 months ago

1.0.0-6629cb2

6 months ago

1.0.0-bfa0fe5

6 months ago

0.3.2-28610be

7 months ago

0.3.1-9eb8ab5

10 months ago

1.0.0-572880f

6 months ago

0.3.1-8ac0677

9 months ago

1.0.0-c1dac36

6 months ago

0.3.2-5516ff0

7 months ago

0.3.2-be1e088

7 months ago

0.3.2-968cac3

7 months ago

0.3.2-331ee21

7 months ago

0.3.1-f23d4c6

9 months ago

1.0.0-80e9ff6

6 months ago

0.3.1-1a491fd

10 months ago

0.3.2-5b355f8

7 months ago

1.0.0-4e83456

6 months ago

0.3.2-69b1245

7 months ago

0.3.2-7dfdba3

8 months ago

0.3.1-8c74a5f

9 months ago

0.3.1-7871d39

9 months ago

0.3.2-da56158

7 months ago

0.3.2-889006a

8 months ago

1.0.0-a8bfa8e

6 months ago

1.0.0-e388da1

6 months ago

0.3.1-04901e2

9 months ago

0.3.2-648869d

9 months ago

0.3.1

11 months ago

0.3.0

12 months ago

0.2.2

12 months ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago