reactjs - 从 puppeteer 登录后如何为主页运行灯塔
问题描述
我添加了两个 npm "@lhci/cli" 和 puppeteer。之后我添加了两个配置文件
- lighthouserc.js :配置细节是:
module.exports = {
ci: {
upload: {
target: 'temporary-public-storage'
},
collect: {
puppeteerScript: 'puppeteer-script.js',
chromePath: puppeteer.executablePath(),
url: ["https://myWebsite.com/abc"],
headful: true,
numberOfRuns: 1,
disableStorageReset: true,
setting: {
disableStorageReset: true
},
puppeteerLaunchOptions: {
slowMo: 20,
headless: false,
disableStorageReset: true
}
},
assert: {
assertions: {
'categories:performance': ['warn', { minScore: 1 }],
'categories:accessibility': ['error', { minScore: 0.5 }]
}
}
}
};
- puppeteer-script.js
module.exports = async (browser, context) => {
await page.setDefaultNavigationTimeout(90000);
await page.goto(context.url);
await page.type('input[type=text]', 'abc');
await page.type('input[type=email]', 'abc@abc.com');
await page.type('input[type=password]', 'abc@100');
await page.click('[type="button"]');
await page.waitForNavigation({ waitUntil: "networkidle2" })
await page.close();
};
在 package.json 我添加了脚本命令:
"test:lighthouse": "lhci autorun --collect.settings.chromeFlags='--no-sandbox'"
现在登录工作正常,但我想为我在 lighthouserc.js ( https://myWebsite.com/abc )中指定的 url 运行灯塔。但是登录后它试图访问 url 并且再次登录屏幕来了,灯塔正在测量登录页面的性能。
是否可以在我在配置中指定的 url 上运行灯塔。请帮助我。 https://myWebsite.com/abc是我的 reactjs 应用程序
解决方案
推荐阅读
- python - 使用 defaultdict 对 pandas 中的值进行 bin 处理
- python - 在我的情况下,“str”类型对象的未知格式代码“f”是什么意思?
- jquery - Wordpress 网站 jeguery 移动响应式切换菜单不起作用
- javascript - 点击JS后汉堡菜单不消失
- internationalization - Hugo:如何在 URL 中翻译组名
- flutter - I/flutter:FormatException:输入意外结束(在字符 1 处)
- bots - 有没有办法制作一个仅适用于 1 人的反垃圾邮件机器人?
- ios - 如何从 iOS 共享文件?
- typescript - 根据枚举成员区分函数和对象类型
- perl - Perl 在文件中搜索内容并使用正则表达式取出值