Created
November 27, 2020 16:20
-
-
Save weyert/da4d2cb1f4356dc429d1348ea61c6b86 to your computer and use it in GitHub Desktop.
Helper method to use DOM Testing Library inside frames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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