从puppeteer登录后如何为首页运行灯塔

问题描述

添加了两个npm“ @ lhci / cli”和puppeteer。之后我添加了两个配置文件

  1. 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 }]
      }
    }
  }
};
  1. 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运行lighthouse。 但是登录后,它试图访问url,再次出现登录屏幕,灯塔正在评估登录页面性能

是否可以在配置中指定的网址上运行lighthouse。请协助我。 https://myWebsite.com/abc是我的reactjs应用程序

解决方法

我还没有关于您网站工作流程的完整信息,但是正如configuration guide puppeteer脚本中提到的那样,lhci配置文件中提到的每个URL都运行。

运行操纵up脚本后,灯塔将打开URL。现在,如果您的站点再次打开登录页面,则很可能是您的应用或配置存在问题。您的应用未正确设置Cookie或登录过程因某种原因失败,您需要进行检查。

此外,由于puppeteer脚本将针对配置中的每个URL运行,因此最好不要重新登录(如果您已经登录过一次),请在Github上检出this issue