Integrating Lighthouse to your Test Automation Framework

Akanksha Gupta
Jul 2 · 3 min read

Are you exploring -

  1. How to do performance testing using automation?
  2. What all matrices should be taken care of while measuring performance, accessibility testing?
  3. what is my status of SEO?
  4. what all are the best development practices?
  5. which tool I can use to make it possible — any open-source tool that is authenticated?

if Yes, then I guess this 5 min read can do wonders for you.

Google Lighthouse is an open-source, automated tool for measuring the quality of web pages. Lighthouse audits performance, accessibility, and search engine optimization of web pages.

Pre-requisite :

  1. Node installation

Initial Setup :

  1. Create an npm project. Run "npm init"
  2. Install Typescript if you are using TS. Run “npm i -g typescript” and “npm i — save-dev typescript
  3. Install Chrome launcher. Run "npm install -g chrome-launcher"
  4. Install Lighthouse to your project. Run “npm install -g lighthouse

Steps :

1. Create a data source with a set of your URLs and Page name that you want to give (Page name is optional, just to make report name readable).

Note: You can use JSON or EXCEL sheet to read your data if you have bulky data.

2. Create a TS or JS File in your working directory. Let's start with our code -

a. Do the setup to create a Report directory (sub-folders based on CurrentDate and Time) and initialize the chrome launcher.

b. Initialise your lighthouse auditor and store the results in your report folder.

Audit Your one URL and store that into a Report

You can leverage the above code for all URLs present in your data source, by running in Loop.

c. Run your File by "node <your file path>"

d. Your report will be generated in the Reports/{CurrentdateTime} folder of your project directory.

e. Open an Html file to your page in any browser. You will get a detailed report.

Lighthouse Report sample

References:

Code Location for reference: https://github.com/akagupta9/lighthouse-wrapper

Lighthouse Npm package: https://www.npmjs.com/package/lighthouse

Other Scopes :

  1. You can include jest/mocha-related test cases to verify a certain section of properties you are looking for as a high priority.
  2. You can include this as a Jenkins pipeline and make it scheduled (Add email capabilities to it )

Hey, You are all set.

Stay tuned for my next blog on the dockerizing lighthouse.

TestVagrant

Solving testing problems intuitively and intelligently

TestVagrant

Testvagrant is a test engineering company which helps shape the testing strategy and take Products a step closer to having a faster, accurate, and more predictable release.

Akanksha Gupta

Written by

SDET | https://www.linkedin.com/in/akanksha-gupta-48784710a/ | https://github.com/akagupta9?tab=repositories

TestVagrant

Testvagrant is a test engineering company which helps shape the testing strategy and take Products a step closer to having a faster, accurate, and more predictable release.