web页面性能检测工具Lighthouse

 🔥 交流讨论:欢迎加入我们一起学习!

🔥 资源分享耗时200+小时精选的「软件测试」资料包

🔥 教程推荐:火遍全网的《软件测试》教程  

📢欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!

> About Automated auditing, performance metrics, and best practices for the web.

Lighthouse 可以自动检查Web页面的性能。

你可以以多种方式使用它。

浏览器插件

作为浏览器插件,访问chrome网上商店 搜索`Lighthouse` 插件安装。以两种方式使用。

* 方式

 安装成功后,访问想要检查的页面,开发插件,点击`Generate report`,稍等片刻,你将会得到一份页面的检查报告。

* 方式二

访问想要检查的页面,打开开发者工具,切换到`Lighthouse` 标签使用。

Node CLI

以Node CLI方式使用Lighthouse可以得到最大灵活性,Lighthouse提供了许多参数使用。

> Linghthouse 需要Node 14 LTS(14.x) 或更高版本。

  • 安装

> npm install -g lighthouse
 
  • 查看帮助

> lighthouse --help
 
  • 使用

> lighthouse https://www.baidu.com --output html --output-path ./report.html
 
√ We're constantly trying to improve Lighthouse and its reliability.
...

`--output` 指定报告的类型;`--output-path` 指定报告的路径。

图片 

以编程模式使用

创建`lighthouse_demo.js` 文件,脚本如下:

const fs = require('fs');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
 
(async () => {
  const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
  const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};
  const runnerResult = await lighthouse('https://www.baidu.com/', options);
 
 
  // `.report` is the HTML report as a string
  const reportHtml = runnerResult.report;
  fs.writeFileSync('lhreport.html', reportHtml);
 
  // `.lhr` is the Lighthouse Result as a JS object
  console.log('Report is done for', runnerResult.lhr.finalUrl);
  console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
  
  await chrome.kill();
}

有没有自动化脚本既视感,还可以设置 `headless`模式。

  • 运行

> node lighthouse_demo.js

 

最终,会在当前目录下生成 `lhreport.html` 结果文件。

Web网站

有一些Web网站基于lighthouse 提供服务,你可以登录这些网站输入URL检测网络性能。

* Web Page Test

https://www.webpagetest.org/

* Calibre

https://calibreapp.com/

* Debug bear

https://www.debugbear.com/
 

* Lighthouse Keeper

https://lighthouse-keeper.com/

...

以 Web Page Test 为例:

最后我邀请你进入我们的【软件测试学习交流群:785128166】, 大家可以一起探讨交流软件测试,共同学习软件测试技术、面试等软件测试方方面面,还会有免费直播课,收获更多测试技巧,我们一起进阶Python自动化测试/测试开发,走向高薪之路

作为一个软件测试的过来人,我想尽自己最大的努力,帮助每一个伙伴都能顺利找到工作。所以我整理了下面这份资源,现在免费分享给大家,有需要的小伙伴可以关注【公众号:程序员二黑】自提!

  • 25
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值