我添加了两个 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 应用程序