( page: Page, selector: string, text: string, )
| 293 | } |
| 294 | |
| 295 | export async function waitForText( |
| 296 | page: Page, |
| 297 | selector: string, |
| 298 | text: string, |
| 299 | ) { |
| 300 | await page.waitForSelector(selector); |
| 301 | try { |
| 302 | await page.waitForFunction( |
| 303 | (sel: string, value: string) => { |
| 304 | const el = document.querySelector(sel); |
| 305 | if (el === null) return false; |
| 306 | return el.textContent === value; |
| 307 | }, |
| 308 | { args: [selector, String(text)] }, |
| 309 | ); |
| 310 | } catch (err) { |
| 311 | const body = await page.content(); |
| 312 | // deno-lint-ignore no-explicit-any |
| 313 | const pretty = prettyDom(parseHtml(body) as any); |
| 314 | |
| 315 | // deno-lint-ignore no-console |
| 316 | console.log( |
| 317 | `Text "${text}" not found on selector "${selector}" in html:\n\n${pretty}`, |
| 318 | ); |
| 319 | throw err; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | export async function waitFor( |
| 324 | fn: () => Promise<unknown> | unknown, |
no test coverage detected