test: throw element not found error (#12665)

This commit is contained in:
sun0day 2023-03-31 01:22:08 +08:00 committed by GitHub
parent 363fa31e9b
commit 1f011d8e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,7 +71,11 @@ const timeout = (n: number) => new Promise((r) => setTimeout(r, n))
async function toEl(el: string | ElementHandle): Promise<ElementHandle> {
if (typeof el === 'string') {
return await page.$(el)
const realEl = await page.$(el)
if (realEl == null) {
throw new Error(`Cannot find element: "${el}"`)
}
return realEl
}
return el
}