import type { Page, Expect } from '@playwright/test'; import { pageWithBody } from './fixtures.js'; // An `; } export const framesSpec = async (page: Page, expect: Expect): Promise => { await page.goto(pageWithBody(`

outside

${iframeWithBody('app', `

inside

${iframeWithBody('nested', '

deep

')} `)} `)); const app = page.frameLocator('#app'); // Locators resolve inside the iframe's document, not the page's. await expect(app.getByText('inside')).toBeVisible(); await expect(page.getByText('inside')).toHaveCount(0); await expect(app.getByText('outside')).toHaveCount(0); await expect(app.locator('li')).toHaveCount(3); await expect(app.getByRole('listitem').nth(1)).toHaveText('two'); // Actions reach elements inside the iframe. await app.getByRole('button', { name: 'press me' }).click(); await expect(app.locator('#b')).toHaveText('clicked'); await app.locator('#name').fill('hello'); await expect(app.locator('#name')).toHaveValue('hello'); expect(await app.locator('#name').inputValue()).toBe('hello'); // contentFrame() is the same frame, reached from a locator of the