从 puppeteer 登录后如何为主页运行灯塔 [英] How to run lighthouse for the homepage after login from puppeteer

查看:45
本文介绍了从 puppeteer 登录后如何为主页运行灯塔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了两个 npm "@lhci/cli";和 puppeteer.之后我添加了两个配置文件

I added two npm "@lhci/cli" and puppeteer.After that I added two config file

  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 中我添加了脚本命令:

and in package.json I added script command as :

"test:lighthouse": "lhci autorun --collect.settings.chromeFlags='--no-sandbox'" 

现在登录工作正常,但我想为我在 lighthouserc.js 中指定的 url 运行灯塔 (https://myWebsite.com/abc).但是登录后,它会尝试访问 url,然后登录屏幕再次出现,灯塔正在测量登录页面的性能.

Now Login is working fine but I want to run the lighthouse for the url that I specified in lighthouserc.js (https://myWebsite.com/abc). But after login it is trying to access the url and again login screen is coming and the lighthouse is measuring performance for the login page.

是否可以在我在配置中指定的 url 上运行灯塔.请帮助我.https://myWebsite.com/abc 是我的 reactjs 应用程序

Is it possible to run lighthouse on url I specified in the config.Please assist me. https://myWebsite.com/abc is my reactjs application

推荐答案

我没有关于您网站工作流程的完整信息,但在 配置指南 puppeteer 脚本针对 lhci 配置文件中提到的每个 url 运行.

I do not have complete information on the workflow of your site but as mentioned in the configuration guide puppeteer script is run for each url mentioned in the lhci config file.

运行 puppeteer 脚本后,lighthouse 将打开 URL.现在,如果您的站点再次打开登录页面,则很可能是您的应用程序或配置存在问题.您的应用程序未正确设置 cookie 或登录过程以某种方式失败,您需要检查这一点.

And after puppeteer script is ran, lighthouse will open URL. Now if your site is opening login page again, that its an issue with your app or configuration most likely. Either your app is not setting cookie correctly or login process is failing somehow, you will need to check that.

此外,由于 puppeteer 脚本将针对配置中的每个 url 运行,如果您已经登录过一次,最好不要重新登录,请查看 这个问题 在 Github 上.

Also, as puppeteer script will be running for every url in the config, its good idea to not re-login if you already logged in once, check out this issue on Github.

这篇关于从 puppeteer 登录后如何为主页运行灯塔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆