Skip to content

Instantly share code, notes, and snippets.

@weyert
Created November 27, 2020 16:20
Show Gist options
  • Save weyert/da4d2cb1f4356dc429d1348ea61c6b86 to your computer and use it in GitHub Desktop.
Save weyert/da4d2cb1f4356dc429d1348ea61c6b86 to your computer and use it in GitHub Desktop.
Helper method to use DOM Testing Library inside frames
async function getFrameDocument(frame: Frame): Promise<ElementHandle> {
const documentHandle = await frame.evaluateHandle<Node>('document')
const document = documentHandle.asElement()
if (!document) {
throw new Error('Failed to find Document in frame')
}
return document
}
async function getQueriesByFrame(frame: Frame) {
const frameDocument = await getFrameDocument((frame as unknown) as Frame)
const frameQueries = getQueriesForElement(frameDocument)
return frameQueries
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment