Insights

Effortlessly Perform Complex Load Testing with Artillery and Playwright

Photo of the author: Felipe Gonzalez

Felipe Gonzalez

  •  

2 min read.

This week, I want to share how to perform load testing with complex flows easily using Artillery and Playwright.

Creating an End-to-End Test with Playwright

You can create end-to-end tests with Playwright in two ways:

  1. Writing the code directly.
  2. Using a Chrome extension called Playwright CRX.

We will use the extension for simplicity, but if you prefer coding, you can refer to the official Playwright documentation.

Steps to Create a Test with Playwright CRX

  1. Install the extension Playwright CRX
  2. Open the extension and record the flow you want to test.
  3. Export the script.
  4. Save the script as axiacore.com.js.
// axiacore.com.js
module.exports = { AxiacoreFlow };

async function AxiacoreFlow(page, vuContext, events, test) {
    const { step } = test;
    await step('home', async () => {
        await page.goto('https://axiacore.com');
        await page.getByLabel('Global').getByLabel('portfolio').click();
    });
};


Creating a Load Test with Artillery

1. Install Artillery

npm install -g artillery

2. Create a Configuration File for the Load Test

# artillery.yaml
config:
  target: <a href="https://axiacore.com" class="redactor-autoparser-object">https://axiacore.com</a>
  # Load the Playwright engine:
  engines:
    playwright:
      trace: true  # Enable Playwright trace
  # Path to the JavaScript file that defines Playwright test functions
  processor: './axiacore.js'  # Path to JavaScript file that defines Playwright test functions
scenarios:
  - engine: playwright
    testFunction: 'AxiacoreFlow'

3. Run the Load Test

artillery run artillery.yaml
Artillery will run the test and automatically record front-end performance metrics that measure perceived load speed such as LCP and FCP:
--------------------------------
Summary report @ 11:24:53(+0100)
--------------------------------
vusers.created.total: ....................................... 1
vusers.completed: ........................................... 1
vusers.session_length:
  min: ...................................................... 5911.7
  max: ...................................................... 5911.7
  mean: ..................................................... 5911.7
  median: ................................................... 5944.6
  p95: ...................................................... 5944.6
  p99: ...................................................... 5944.6
browser.page.FCP.https://axiacore.com/:
  min: ...................................................... 1521.1
  max: ...................................................... 1521.1
  mean: ..................................................... 1521.1
  median: ................................................... 1525.7
  p95: ...................................................... 1525.7
  p99: ...................................................... 1525.7
browser.page.LCP.https://axiacore.com/:
  min: ...................................................... 1521.1
  max: ...................................................... 1521.1
  mean: ..................................................... 1521.1
  median: ................................................... 1525.7
  p95: ...................................................... 1525.7
  p99: ...................................................... 1525.7
browser.page.FCP.https://axiacore.com/cloud/:
  min: ...................................................... 205.3
  max: ...................................................... 205.3
  mean: ..................................................... 205.3
  median: ................................................... 206.5
  p95: ...................................................... 206.5
  p99: ...................................................... 206.5
browser.page.LCP.https://axiacore.com/cloud/:
  min: ...................................................... 205.3
  max: ...................................................... 205.3
  median: ................................................... 206.5
  p95: ...................................................... 206.5
  p99: ...................................................... 206.5

Conclusions

Using Artillery and Playwright, you can effortlessly perform load testing, even for complex workflows. These tools not only simplify the process but also allow you to automate load tests, ensuring they run periodically. This automation helps detect issues promptly, keeping your application reliable and robust. By integrating these practices, you can enhance your testing efficiency and maintain high performance standards for your web applications.

Learn more by receiving an email once a month.

Additional Insights

Cyberattacks will cost 9.5 trillion dollars in 2024

“If it were measured as a country, cybercrime would be the third largest economy after United States and China.” CS Ventures

Author Michel Binder Michel Binder