Automated Accessibility & Performance Testing for Web Based Applications
The below document details out how to setup and perform Automated Accessibility & Performance Test along with generating detailed Test Results using Lighthouse. It also includes the setup required to perform this automated test on a list of URL's as a batch.
Prerequisites:
- Nodejs
- Install Google Lighthouse by Node.js
Installation command line:
npm install -g lighthouse
Once it’s completed, you can try running this command line
lighthouse https://www.google.com
This will generate the results in html (default) format. The location of results will be displayed on the command window.
Customizing lighthouse:
Use below command line for all customization options
lighthouse –help
Headless & Quiet mode:
If you want headless and without log in command line
lighthouse --quiet --chrome-flags=”--headless” https://www.google.com
Categories:
It is also possible to choose which categories you want to report on. Following categories are available to be included in the report:
- Performance
- Accessibility
- Best Practices
- SEO
- PWA
Example with default all categories.
lighthouse --only-categories=SEO https://www.google.com
Example for multiple categories:
lighthouse --only-categories=SEO --only-categories=performance https://www.google.com
Desktop Vs Mobile
We can simulate both Desktop and Mobile behavior of application under test.
--emulated-form-factor=desktop --emulated-form-factor=mobile
Generating Report for Multiple URL’s
We can also build a batch file which can generate report for multiple URL’s and help save time.
- Create a batch-file with your any text editor. Paste the following code into it:
@For /F "UseBackQ Delims=" %%A In ("URLS.txt") Do @LightHouse "%%A" --quiet --chrome-flags="--headless" --emulated-form-factor=desktop -disable-storage-reset --throttling-method=provided -- preset=perf –
- Create text file with list of all URL’s you would like to be part of batch test.
- Run the script. Go back to the command prompt and navigate to the folder where the two files were saved.
cd <Nav URL>
Example with folder:
cd C:\Users\SourabhGoel\Download\Lighthouse\
All you should need to do now is running the command below:
<name of batch-file>.bat
Working with Web-pages which require Authentication:
There are multiple options to handle the authentication.
Puppeteer - a browser automation tool - can be used to pro grammatically setup a session.
Launch a new browser. Navigate to the login page. Fill and submit the login form. Run Lighthouse using the same browser.
Below are Sample Test Results
References:
- Github
- Lighthouse https://developers.google.com/web/tools/lighthouse
Sourabh Goel
TECH-Sales-Marketing & Strategic Projects
P I M C O | Newport Beach, California
Please consider the environment before printing this article
Nice sir
Good Read