web性能检测工具lighthouse

软件测试资料领取:[内部资源] 想拿年薪40W+的软件测试人员,这份资料必须领取~

软件测试面试刷题工具:软件测试面试刷题【800道面试题+答案免费刷】

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 为例:

既然看到这里,希望点赞收藏支持一下!期待 ~

最后感谢每一个认真阅读我文章的人,下方这份完整的软件测试教程已经整理上传完成,需要的朋友们可以文末自行领取:【保证100%免费】

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值