(
dom?: Element | Locator | undefined | null,
maxLength: number = Number(defaultOptions?.maxLength ?? import.meta.env.DEBUG_PRINT_LIMIT ?? 7000),
prettyFormatOptions: PrettyDOMOptions = {},
)
| 507 | } |
| 508 | |
| 509 | function prettyDOM( |
| 510 | dom?: Element | Locator | undefined | null, |
| 511 | maxLength: number = Number(defaultOptions?.maxLength ?? import.meta.env.DEBUG_PRINT_LIMIT ?? 7000), |
| 512 | prettyFormatOptions: PrettyDOMOptions = {}, |
| 513 | ): string { |
| 514 | if (maxLength === 0) { |
| 515 | return '' |
| 516 | } |
| 517 | |
| 518 | if (!dom) { |
| 519 | dom = document.body |
| 520 | } |
| 521 | |
| 522 | if ('element' in dom && 'all' in dom) { |
| 523 | dom = dom.element() |
| 524 | } |
| 525 | |
| 526 | const type = typeof dom |
| 527 | if (type !== 'object' || !dom.outerHTML) { |
| 528 | const typeName = type === 'object' ? dom.constructor.name : type |
| 529 | throw new TypeError(`Expecting a valid DOM element, but got ${typeName}.`) |
| 530 | } |
| 531 | |
| 532 | const pretty = stringify(dom, Number.POSITIVE_INFINITY, { |
| 533 | maxLength, |
| 534 | highlight: true, |
| 535 | ...defaultOptions, |
| 536 | ...prettyFormatOptions, |
| 537 | }) |
| 538 | return dom.outerHTML.length > maxLength |
| 539 | ? `${pretty.slice(0, maxLength)}...` |
| 540 | : pretty |
| 541 | } |
| 542 | |
| 543 | function getElementError(selector: string, container: Element): Error { |
| 544 | const error = new Error(`Cannot find element with locator: ${__INTERNAL._asLocator('javascript', selector)}\n\n${prettyDOM(container)}`) |
no test coverage detected