/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { test as it, expect } from './pageTest'; function snapshotForAI(page: any): Promise { return page._snapshotForAI(); } it('should generate refs', async ({ page }) => { await page.setContent(` `); const snapshot1 = await snapshotForAI(page); expect(snapshot1).toContainYaml(` - generic [ref=e1]: - button "One" [ref=e2] - button "Two" [ref=e3] - button "Three" [ref=e4] `); await expect(page.locator('aria-ref=e2')).toHaveText('One'); await expect(page.locator('aria-ref=e3')).toHaveText('Two'); await expect(page.locator('aria-ref=e4')).toHaveText('Three'); await page.locator('aria-ref=e3').evaluate((e: HTMLElement) => { e.textContent = 'Not Two'; }); const snapshot2 = await snapshotForAI(page); expect(snapshot2).toContainYaml(` - generic [ref=e1]: - button "One" [ref=e2] - button "Not Two" [ref=e5] - button "Three" [ref=e4] `); }); it('should list iframes', async ({ page }) => { await page.setContent(`

Hello

`, { waitUntil: 'domcontentloaded' }); const snapshot = await snapshotForAI(page); expect(snapshot).toContainYaml(` - generic [ref=e1]: - paragraph [ref=e2]: Test - iframe [ref=e3] `); }); it('should auto-wait for navigation', async ({ page, server }) => { await page.goto(server.PREFIX + '/frames/frame.html'); const [, snapshot] = await Promise.all([ page.evaluate(() => window.location.reload()), snapshotForAI(page) ]); expect(snapshot).toContainYaml(` - generic [ref=e2]: Hi, I'm frame `); }); it('should auto-wait for blocking CSS', async ({ page, server }) => { server.setRoute('/css', (req, res) => { res.setHeader('Content-Type', 'text/css'); setTimeout(() => res.end(`body { monospace }`), 1000); }); await page.setContent(`

Hello World

`, { waitUntil: 'commit' }); expect(await snapshotForAI(page)).toContainYaml('Hello World'); });