Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way I can automate auth, for pages that need a user to be logged in? #109

Open
misabel opened this issue Sep 30, 2022 · 3 comments

Comments

@misabel
Copy link

misabel commented Sep 30, 2022

No description provided.

@maecapozzi
Copy link

For anyone who comes across this -- you can use puppeteer to automate authentication.

@gustavolzangelo
Copy link

For anyone who comes across this -- you can use puppeteer to automate authentication.

Do you have any good tutorials about it?

@maecapozzi
Copy link

Hey! I haven't found a good a good tutorial, but I can share some code snippets for how I ended up doing it here.

lighthouserc.json

{
  "ci": {
    "collect": {
      "puppeteerScript": "lighthouse-audits/puppeteerLogin.js",
      "url": [
        "https://website.com/home",      
      ]
    }
  }
}

lighthouse-audits/puppeteerLogin.js

const login = async (page, origin) => {
  await page.goto(origin);
  await page.waitForSelector('[data-testid=login-input-email]', {
    visible: true,
  });

  // Fill in and submit login form.
  const emailInput = await page.$('[data-testid=login-input-email]');
  await emailInput.type('email@email.com');

  const passwordInput = await page.$('[data-testid=login-input-password]');
  await page.click('[data-testid="login-input-password"]');
  await passwordInput.type('password');

  await Promise.all([
    page.click('[data-testid="login-button"]'),
    page.waitForNavigation(),
  ]);

  page.close();
};

module.exports = async (browser) => {
  const page = await browser.newPage();
  const url = "https://website.com/login"

  await login(
    page,
    'https://analytics.amplitude.com/login/e2e-tests/?no_captcha=1&no_throttle=1',
  );
};

Let me know if this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants