Closed grybykm closed 2 years ago
Hi @grybykm this makes a lot of sense.
Kindly raise a PR. This will be a breaking change though
It should not be a breaking change I believe unless we want to drop page
support completely.
Btw, I'm setting up lighthouse like this
import os from 'os'
import path from 'path'
import { chromium, test as base } from '@playwright/test'
import type { BrowserContext } from '@playwright/test'
import getPort from 'get-port' // version ^5.1.1 due to issues with imports in playwright 1.20.1
export const lighthouseTest = base.extend<{ context: BrowserContext }, { port: number }>({
port: [
async ({}, use) => {
// Assign a unique port for each playwright worker to support parallel tests
const port = await getPort()
await use(port)
},
{ scope: 'worker' },
],
context: [
async ({ port, launchOptions }, use) => {
const context = await chromium.launchPersistentContext(path.join(os.tmpdir(), 'pw', `${Math.random()}`.replace('.', '')), {
args: [...(launchOptions.args || []), `--remote-debugging-port=${port}`],
})
// apply state previously saved in the the `globalSetup`
await context.addCookies(require('../../state-chrome.json').cookies)
await use(context)
await context.close()
},
{ scope: 'test' },
],
})
ref to globalSetup https://playwright.dev/docs/test-auth
Additionally, I use global teardown to cleanup the tmp folder
import os from 'os'
import path from 'path'
import rimraf from 'rimraf'
function globalTeardown() {
rimraf(path.join(os.tmpdir(), 'pw'), console.log)
}
export default globalTeardown
@grybykm looks great. Let's do this.
Concern
Opening a page one extra time more and keeping it opened consumes 2 times more resources. It's especially noticeable when running tests in parallel.
There is no real need to pass
page
toplayAudit
. It's used to perform some validations and get the url.Solution
An option to pass url string instead of page.
ex: if page is string use it as url and skip all the checks.
I can raise the PR if you are ok with this.
Thank you