Iframe
sexta13 opened this issue · 2 comments
Can we use this with an Iframe? is there any example? Thanks
Hi @sexta13, I'm sorry it's taken me so long to get back to you. This library doesn't explicitly support iframes, but I don't think it would be too hard to add support.
We'd need to update the getDocument method to target the frame, so maybe just adding an options argument that would take a frameSelector...
// ↯ ---------- New API ---------- ↯
const frame = await getDocument(page, { frame: { url: /google\.com/ } })
const input = await getByLabelText(frame, 'search')The @playwright/test fixture API would be a little trickier... it would depend on the above change, and then maybe provide queries for each frame?
import {test as baseTest} from '@playwright/test'
import {fixturesFor, TestingLibraryFixtures} from '@playwright-testing-library/test/fixture'
// New API
const fixtures = fixturesFor({ google: { url: /google\.com/ }, bing: { url: /bing\.com/ } });
const test = baseTest.extend<TestingLibraryFixtures>(fixtures))
const { expect } = test
// Queries available for each frame... `main` is always available to query `page.mainFrame()`?
test('iframes with search inputs', async ({ queries: { main, google, bing } }) => {
const inputFromMainFrame = await main.getByLabelText('search');
const inputFromGoogleFrame = await main.getByLabelText('search');
const inputFromBingFrame = await main.getByLabelText('search');
// ...
})I left links above with where the modifications would need to be made.
Out of curiousity, what's your use case? Would you be querying the main frame as well as an iframe? What do you think of this API?
Hey,
No problem...
Where I work there's a main application (not an iframe) with a menu that opens different applications, and these are inside iframes (mostly one at a time...)
So I would have to query the main app and the app inside the iframe.
Regarding that API, it seems good to me... As it even enables multiple iframes and so. Good work ;)
Is it expectable to have a new release with this?
Thanks.