How to run lighthouse for the homepage after login from puppeteer

Viewed 1631

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

  1. lighthouserc.js : config details are:

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();
};

and in package.json I added script command as :

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

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.

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

1 Answers

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.

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.

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.

Related