Design a site like this with WordPress.com
Get started

How to create a simple performance test with Puppeteer

Creating your first performance test can seem daunting, but it need not be so. This blog post is a guide to resources that you can use to create a simple automated performance test.

A good tool to use to create a performance test is Puppeteer. Puppeteer is a node.js library that can be used to automate chrome. There is good documentation for puppeteer both on its website and helpful posts on discussion groups and other websites such as stackoverflow. There is no need to buy a load testing tool as puppeteer can be downloaded for free.

Puppeteer is a node library so if you have not already done so, you will need to install Node. Node can be downloaded from here: https://nodejs.org/en/download/

You will also need to install Puppeteer and instructions to install Puppeteer are here: https://www.npmjs.com/package/puppeteer

Puppeteer contains functions such as await page.click and page.waitForSelector which you can use to create an automated test. You should use puppeteer to automate the steps that you want a performance test for. You could use the puppeteer example of a functional test on GitHub to help you automate these steps, and you could also use the tutorials on https://pptr.dev/ to help you.

Once you have automated the steps that you want to test for performance, you then need to add code to the test that will give you a timing for the steps that you are interested in. 

For a simple test you can also get the start time and end time of the steps in the test by using new Date() to create timestamps and then calculate the difference between the two timestamps to show how long the steps took:

let beginTime = new Date();

 // steps for the test

let endTime = new Date(); 

let duration = endTime.getTime() – beginTime.getTime();

It is useful to add additional metrics to help interpret the results of the performance test. Chrome dev tools makes available via its api a number of metrics, such as heap size. These metrics can help you interpret the results of the performance test: https://chromedevtools.github.io/devtools-protocol/tot/Performance/#method-getMetrics. This blog post contains an example of how to get the chrome dev tools runtime performance metrcs: https://addyosmani.com/blog/puppeteer-recipes/

The node app that you have created with puppeteer can be deployed to the platform that your team uses and scheduled to run however often you require. 

You will want to share the results of the performance tests. You can write the results of the performance tests to a Geckoboard dataset and this enables you to create a dashboard to display the results of the tests. Geckoboard dashboards can contain a range of visualisations and can be sent to either a Slack channel or an email address on a schedule or displayed on a TV.

Creating an automated performance test creates data that enables you to ask questions about why the performance of your application is as it is and explore further the performance of your application. I hope that this blog post helps you to create a performance test and explore the performance of the application that you are testing.

Resources:

Advertisement

Published by Mike Harris

Mike has been working in testing for 20 years and is currently the lone tester for Geckoboard. He has been a Test Lead and has also worked as a part of waterfall, lean and agile teams. He is also Programme Secretary of BCS SIGiST. Mike has a B.Sc.(HONS) from Middlesex University and is an Associate of the University of Hertfordshire. He has set up and led a Testing Community of Practice and been part of a successful agile transition. He is Co-Programme Chair of the British Computer Society’s Specialist Interest Group in Software Testing. He also contributed to the e-book Testing Stories and has had articles published by the Ministry of Testing. Follow Mike on Twitter: @TestAndAnalysis

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: