-
Notifications
You must be signed in to change notification settings - Fork 85
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
Comments
For anyone who comes across this -- you can use puppeteer to automate authentication. |
Do you have any good tutorials about it? |
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 protected]');
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! |
fyi here is a link to the official example: https://googlechrome.github.io/lighthouse-ci/docs/configuration.html#puppeteerscript |
No description provided.
The text was updated successfully, but these errors were encountered: