18. February 2021
Audits des sites web automatisés avec Lighthouse et QF-Test
What is Lighthouse?
Lighthouse, an open-source tool which was developed by Google, makes it possible to analyze your website in the four categories performance, accessibility, best practices and SEO. To analyze each category, Lighthouse runs a barrage of tests called audits. Depending on the results of the audits, the respective category will get a score between 0 and 100 (see Figure 1).
The performance category analyzes how quickly a website loads and how quickly users can access or view the content. The corresponding score will be influenced by metrics like First Contentful Paint or Time to Interactive. First Contentful Paint indicates the time before the first text or image becomes visible to users while Time to Interactive measures how long it takes a page to become fully interactive.
Accessibility ensures that people with disabilities can access content and navigate the site effectively. One audit used to determine this category's score is checking whether images have been assigned an ALT-attribute. They allow reader programs to describe the image's content for visually impaired people.
The third category makes sure that your site follows standard best practices for the web. For example, does it avoid deprecated APIs and does it only embed resources from secure sources?
Finally, SEO checks how well your page is optimized for search engine result rankings.
Integrate Lighthouse audits in QF-Test
The attached test-suite lighthouse.qft contains a procedure "checkLighthouseScores" to start lighthouse audits and check its results. With the help of the procedure's parameters, you can define a warning and/or error limit for each of the four categories (Value must be between 0 and 100). If, let's say, the performance score falls below your specified error limit, QF-Test will inform you with the respective error message (See Figure 2). To deactivate the check of a limit parameter, you just need to set its value to -.
By integrating Lighthouse audits into your automated testing, your site can be continuously checked for unexpected changes. Besides a summary that will be saved in the run-log, the procedure also provides several optional parameters for further configuration. For example, the parameter "mobileEmulation" allows you to analyze your website not only in a desktop but also a smartphone environment.
How to install Lighthouse
The first step is to install the Google Chrome Browser, as Lighthouse analyzes your website using its headless mode.
Please install Google Chrome. The latest version can be downloaded from: https://www.google.com/chrome
To be able to execute the procedure, Lighthouse needs to be installed as a Node.js module.
Install the current long-term support version (LTS) of Node.js. The latest version can be downloaded from: https://nodejs.org/de
After Node.js is installed, please open the command line of your operating system (Windows: command prompt).
Use the opened command line to execute the command shown in figure 3. If Lighthouse should not be installed as a global module, do not use the -g flag.
- To ensure correct installation, execute the command lighthouse in the already opened command line. Following output should appear:
For further information regarding Lighthouse please visit: https://developers.google.com/web/tools/lighthouse
- In case the lighthouse command cannot be found anyway, a missing entry in your path environment variable may be missing. On Windows you may add e.g. %appdata%\npm by hand.
- After installing npm and lighthouse, QF-Test need to be restarted in order to get aware of changes in the envrionment settings.
- Some lighthouse results are dependent on the network connection and machine performance, the audits are executed on. There should be no constraints or your need to take them into account respectively.