abhinaba-ghosh / playwright-lighthouse

:performing_arts:: Playwright Lighthouse Audit
https://www.npmjs.com/package/playwright-lighthouse
MIT License
250 stars 28 forks source link

not opening the state where I left #34

Closed moksh-tehlan closed 2 years ago

moksh-tehlan commented 2 years ago

Hi Everyone, Actually what's happening is I'm trying to test a website where I first put my id and password on first page the when I try to test it using the playAudit it goes back to the login page and start testing over there not on the home page what can I do

badsyntax commented 2 years ago

If you need to persist state then you need to use a persistent context, see: https://github.com/abhinaba-ghosh/playwright-lighthouse#running-lighthouse-on-authenticated-routes

moksh-tehlan commented 2 years ago

it's not working it still can't login here is the code `test('lighthouse audit report', async () => { let page; let mbrowser; const userDataDir = path.join("moksh", "pw", "data"); mbrowser = await chromium.launchPersistentContext(userDataDir, { args: ['--remote-debugging-port=9222'], });

page = await mbrowser.newPage();
await page.goto("https://www.instagram.com/");
const username = "";
const password = "";

const usernamefield = '//label//input[@name="username"]';
const passwordfield = '//label//input[@name="password"]';
const loginbtn = '//div//button[@type="submit"]';
// const notnow = '//div//button[@type="button"]';

try {
    await page.fill(usernamefield, username);
    await page.fill(passwordfield, password);
    await page.click(loginbtn);
    // await page.click(notnow);
    console.log("Element found");
} catch (error) {
    // eslint-disable-next-line no-console
    console.log('*** Element Not Found to click on element***', error);
}

await playAudit({
    page: page,
    // mostly needed is the seo and performance but it won't hurt to add all
    thresholds: {
        performance: 20,
        accessibility: 20,
        'best-practices': 20,
        seo: 20,
        pwa: 20,
    },
    config: lighthouseDesktopConfig,
    port: 9222,
    reports: {
        formats: {
            json: false,
            html: true,
            csv: false,
        },
        name: "lighthouse-report",
        directory: `${process.cwd()}/lighthouse`,
    }
})
await mbrowser.close();

});`

moksh-tehlan commented 2 years ago

It's working there was just a little code problem from my side

CkumarGitHub commented 1 year ago

It's working there was just a little code problem from my side

Could you please share the code problem ? It is not working for me