| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | /** | 
					
						
							|  |  |  |  * 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 { expect, playwrightTest as baseTest } from '../config/browserTest'; | 
					
						
							|  |  |  | import { PlaywrightServer } from '../../packages/playwright-core/lib/remote/playwrightServer'; | 
					
						
							| 
									
										
										
										
											2023-01-13 13:50:38 -08:00
										 |  |  | import { createGuid } from '../../packages/playwright-core/lib/utils/crypto'; | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | import { Backend } from '../config/debugControllerBackend'; | 
					
						
							|  |  |  | import type { Browser, BrowserContext } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  | import type * as channels from '@protocol/channels'; | 
					
						
							| 
									
										
										
										
											2024-11-13 21:33:38 -08:00
										 |  |  | import { roundBox } from '../page/pageTest'; | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 15:54:53 -08:00
										 |  |  | type BrowserWithReuse = Browser & { _newContextForReuse: () => Promise<BrowserContext> }; | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | type Fixtures = { | 
					
						
							|  |  |  |   wsEndpoint: string; | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   backend: channels.DebugControllerChannel; | 
					
						
							| 
									
										
										
										
											2022-12-19 15:54:53 -08:00
										 |  |  |   connectedBrowserFactory: () => Promise<BrowserWithReuse>; | 
					
						
							|  |  |  |   connectedBrowser: BrowserWithReuse; | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const test = baseTest.extend<Fixtures>({ | 
					
						
							| 
									
										
										
										
											2024-11-15 13:43:00 -08:00
										 |  |  |   wsEndpoint: async ({ headless }, use) => { | 
					
						
							|  |  |  |     if (headless) | 
					
						
							|  |  |  |       process.env.PW_DEBUG_CONTROLLER_HEADLESS = '1'; | 
					
						
							| 
									
										
										
										
											2023-05-23 10:56:37 -07:00
										 |  |  |     const server = new PlaywrightServer({ mode: 'extension', path: '/' + createGuid(), maxConnections: Number.MAX_VALUE, enableSocksProxy: false }); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |     const wsEndpoint = await server.listen(); | 
					
						
							|  |  |  |     await use(wsEndpoint); | 
					
						
							|  |  |  |     await server.close(); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   backend: async ({ wsEndpoint }, use) => { | 
					
						
							|  |  |  |     const backend = new Backend(); | 
					
						
							|  |  |  |     await backend.connect(wsEndpoint); | 
					
						
							| 
									
										
										
										
											2022-11-10 12:15:29 -08:00
										 |  |  |     await backend.initialize(); | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |     await use(backend.channel); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:03:04 -04:00
										 |  |  |     await backend.close(); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2022-12-19 15:54:53 -08:00
										 |  |  |   connectedBrowserFactory: async ({ wsEndpoint, browserType }, use) => { | 
					
						
							|  |  |  |     const browsers: BrowserWithReuse [] = []; | 
					
						
							|  |  |  |     await use(async () => { | 
					
						
							| 
									
										
										
										
											2023-08-31 15:29:04 -07:00
										 |  |  |       const browser = await browserType.connect(wsEndpoint, { | 
					
						
							|  |  |  |         headers: { | 
					
						
							|  |  |  |           'x-playwright-launch-options': JSON.stringify((browserType as any)._defaultLaunchOptions), | 
					
						
							|  |  |  |           'x-playwright-reuse-context': '1', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) as BrowserWithReuse; | 
					
						
							| 
									
										
										
										
											2022-12-19 15:54:53 -08:00
										 |  |  |       browsers.push(browser); | 
					
						
							|  |  |  |       return browser; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     for (const browser of browsers) | 
					
						
							|  |  |  |       await browser.close(); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   connectedBrowser: async ({ connectedBrowserFactory }, use) => { | 
					
						
							|  |  |  |     await use(await connectedBrowserFactory()); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test.slow(true, 'All controller tests are slow'); | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  | test.skip(({ mode }) => mode.startsWith('service')); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should pick element', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const events = []; | 
					
						
							|  |  |  |   backend.on('inspectRequested', event => events.push(event)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   await backend.setRecorderMode({ mode: 'inspecting' }); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const [page] = context.pages(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |   await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |   await page.getByRole('button').click(); | 
					
						
							|  |  |  |   await page.getByRole('button').click(); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   expect(events).toEqual([ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-12-12 08:21:53 -08:00
										 |  |  |       ariaSnapshot: '- button "Submit"', | 
					
						
							| 
									
										
										
										
											2022-11-11 15:58:36 -08:00
										 |  |  |       selector: 'internal:role=button[name=\"Submit\"i]', | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |       locator: 'getByRole(\'button\', { name: \'Submit\' })', | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |     }, { | 
					
						
							| 
									
										
										
										
											2024-12-12 08:21:53 -08:00
										 |  |  |       ariaSnapshot: '- button "Submit"', | 
					
						
							| 
									
										
										
										
											2022-11-11 15:58:36 -08:00
										 |  |  |       selector: 'internal:role=button[name=\"Submit\"i]', | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |       locator: 'getByRole(\'button\', { name: \'Submit\' })', | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // No events after mode disabled
 | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   await backend.setRecorderMode({ mode: 'none' }); | 
					
						
							| 
									
										
										
										
											2022-10-24 19:19:58 -04:00
										 |  |  |   await page.locator('body').click(); | 
					
						
							|  |  |  |   expect(events).toHaveLength(2); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should report pages', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const events = []; | 
					
						
							|  |  |  |   backend.on('stateChanged', event => events.push(event)); | 
					
						
							|  |  |  |   await backend.setReportStateChanged({ enabled: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page1 = await context.newPage(); | 
					
						
							|  |  |  |   const page2 = await context.newPage(); | 
					
						
							|  |  |  |   await page1.close(); | 
					
						
							|  |  |  |   await page2.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.setReportStateChanged({ enabled: false }); | 
					
						
							|  |  |  |   const page3 = await context.newPage(); | 
					
						
							|  |  |  |   await page3.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(events).toEqual([ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       pageCount: 1, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |       pageCount: 2, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |       pageCount: 1, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |       pageCount: 0, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should navigate all', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page1 = await context.newPage(); | 
					
						
							|  |  |  |   const page2 = await context.newPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.navigate({ url: 'data:text/plain,Hello world' }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(await page1.evaluate(() => window.location.href)).toBe('data:text/plain,Hello world'); | 
					
						
							|  |  |  |   expect(await page2.evaluate(() => window.location.href)).toBe('data:text/plain,Hello world'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should reset for reuse', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page1 = await context.newPage(); | 
					
						
							|  |  |  |   const page2 = await context.newPage(); | 
					
						
							|  |  |  |   await backend.navigate({ url: 'data:text/plain,Hello world' }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const context2 = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   expect(await context2.pages()[0].evaluate(() => window.location.href)).toBe('about:blank'); | 
					
						
							|  |  |  |   expect(await page1.evaluate(() => window.location.href)).toBe('about:blank'); | 
					
						
							|  |  |  |   expect(await page2.evaluate(() => window.location.href).catch(e => e.message)).toContain('Target page, context or browser has been closed'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should highlight all', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page1 = await context.newPage(); | 
					
						
							|  |  |  |   const page2 = await context.newPage(); | 
					
						
							|  |  |  |   await backend.navigate({ url: 'data:text/html,<button>Submit</button>' }); | 
					
						
							|  |  |  |   await backend.highlight({ selector: 'button' }); | 
					
						
							|  |  |  |   await expect(page1.getByText('locator(\'button\')')).toBeVisible(); | 
					
						
							|  |  |  |   await expect(page2.getByText('locator(\'button\')')).toBeVisible(); | 
					
						
							|  |  |  |   await backend.hideHighlight(); | 
					
						
							|  |  |  |   await expect(page1.getByText('locator(\'button\')')).toBeHidden({ timeout: 1000000 }); | 
					
						
							|  |  |  |   await expect(page2.getByText('locator(\'button\')')).toBeHidden(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should record', async ({ backend, connectedBrowser }) => { | 
					
						
							|  |  |  |   const events = []; | 
					
						
							|  |  |  |   backend.on('sourceChanged', event => events.push(event)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   await backend.setRecorderMode({ mode: 'recording' }); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const [page] = context.pages(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |   await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |   await page.getByRole('button').click(); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   await expect.poll(() => events[events.length - 1]).toEqual({ | 
					
						
							| 
									
										
										
										
											2022-11-01 18:02:14 -07:00
										 |  |  |     header: `import { test, expect } from '@playwright/test';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('test', async ({ page }) => {`,
 | 
					
						
							|  |  |  |     footer: `});`, | 
					
						
							|  |  |  |     actions: [ | 
					
						
							|  |  |  |       `  await page.goto('about:blank');`, | 
					
						
							|  |  |  |       `  await page.getByRole('button', { name: 'Submit' }).click();`, | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  |     text: `import { test, expect } from '@playwright/test';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('test', async ({ page }) => { | 
					
						
							|  |  |  |   await page.goto('about:blank'); | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |   await page.getByRole('button', { name: 'Submit' }).click(); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  | });`
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   // No events after mode disabled
 | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   await backend.setRecorderMode({ mode: 'none' }); | 
					
						
							| 
									
										
										
										
											2024-09-30 20:32:04 +02:00
										 |  |  |   const length = events.length; | 
					
						
							| 
									
										
										
										
											2022-10-27 09:19:55 -07:00
										 |  |  |   await page.getByRole('button').click(); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  |   expect(events).toHaveLength(length); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should record custom data-testid', async ({ backend, connectedBrowser }) => { | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |   // This test emulates "record at cursor" functionality
 | 
					
						
							|  |  |  |   // with custom test id attribute in the config.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  |   const events = []; | 
					
						
							|  |  |  |   backend.on('sourceChanged', event => events.push(event)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |   // 1. "Show browser" (or "run test").
 | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |   const page = await context.newPage(); | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  |   await page.setContent(`<div data-custom-id='one'>One</div>`); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 2. "Record at cursor".
 | 
					
						
							| 
									
										
										
										
											2024-03-20 16:56:29 +01:00
										 |  |  |   await backend.setRecorderMode({ mode: 'recording', testIdAttributeName: 'data-custom-id' }); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 3. Record a click action.
 | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  |   await page.locator('div').click(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |   // 4. Expect "getByTestId" locator.
 | 
					
						
							| 
									
										
										
										
											2022-11-08 12:04:43 -08:00
										 |  |  |   await expect.poll(() => events[events.length - 1]).toEqual({ | 
					
						
							|  |  |  |     header: `import { test, expect } from '@playwright/test';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('test', async ({ page }) => {`,
 | 
					
						
							|  |  |  |     footer: `});`, | 
					
						
							|  |  |  |     actions: [ | 
					
						
							|  |  |  |       `  await page.getByTestId('one').click();`, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     text: `import { test, expect } from '@playwright/test';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('test', async ({ page }) => { | 
					
						
							|  |  |  |   await page.getByTestId('one').click(); | 
					
						
							|  |  |  | });`
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-11-10 12:15:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 15:54:53 -08:00
										 |  |  | test('should reset routes before reuse', async ({ server, connectedBrowserFactory }) => { | 
					
						
							|  |  |  |   const browser1 = await connectedBrowserFactory(); | 
					
						
							|  |  |  |   const context1 = await browser1._newContextForReuse(); | 
					
						
							|  |  |  |   await context1.route(server.PREFIX + '/title.html', route => route.fulfill({ body: '<title>Hello</title>', contentType: 'text/html' })); | 
					
						
							|  |  |  |   const page1 = await context1.newPage(); | 
					
						
							|  |  |  |   await page1.route(server.PREFIX + '/consolelog.html', route => route.fulfill({ body: '<title>World</title>', contentType: 'text/html' })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await page1.goto(server.PREFIX + '/title.html'); | 
					
						
							|  |  |  |   await expect(page1).toHaveTitle('Hello'); | 
					
						
							|  |  |  |   await page1.goto(server.PREFIX + '/consolelog.html'); | 
					
						
							|  |  |  |   await expect(page1).toHaveTitle('World'); | 
					
						
							|  |  |  |   await browser1.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const browser2 = await connectedBrowserFactory(); | 
					
						
							|  |  |  |   const context2 = await browser2._newContextForReuse(); | 
					
						
							|  |  |  |   const page2 = await context2.newPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await page2.goto(server.PREFIX + '/title.html'); | 
					
						
							|  |  |  |   await expect(page2).toHaveTitle('Woof-Woof'); | 
					
						
							|  |  |  |   await page2.goto(server.PREFIX + '/consolelog.html'); | 
					
						
							|  |  |  |   await expect(page2).toHaveTitle('console.log test'); | 
					
						
							|  |  |  |   await browser2.close(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-11-04 14:41:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should highlight inside iframe', async ({ backend, connectedBrowser }, testInfo) => { | 
					
						
							|  |  |  |   testInfo.annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33146' }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page = await context.newPage(); | 
					
						
							|  |  |  |   await backend.navigate({ url: `data:text/html,<div>bar</div><iframe srcdoc="<div>bar</div>"/>` }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await page.frameLocator('iframe').getByText('bar').highlight(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const highlight = page.frameLocator('iframe').locator('x-pw-highlight'); | 
					
						
							|  |  |  |   await expect(highlight).not.toHaveCount(0); | 
					
						
							|  |  |  |   await backend.hideHighlight(); | 
					
						
							|  |  |  |   await expect(highlight).toHaveCount(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.highlight({ selector: `frameLocator('iframe').getByText('bar')` }); | 
					
						
							|  |  |  |   await expect(highlight).not.toHaveCount(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.highlight({ selector: `frameLocator('iframe').frameLocator('iframe').getByText('bar')` }); | 
					
						
							|  |  |  |   await expect(highlight).toHaveCount(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.highlight({ selector: `getByText('bar')` }); | 
					
						
							|  |  |  |   await expect(highlight).toHaveCount(1); | 
					
						
							|  |  |  |   await expect(page.locator('x-pw-highlight')).toHaveCount(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-11-13 21:33:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should highlight aria template', async ({ backend, connectedBrowser }, testInfo) => { | 
					
						
							|  |  |  |   const context = await connectedBrowser._newContextForReuse(); | 
					
						
							|  |  |  |   const page = await context.newPage(); | 
					
						
							|  |  |  |   await backend.navigate({ url: `data:text/html,<button>Submit</button>` }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const button = page.getByRole('button'); | 
					
						
							|  |  |  |   const highlight = page.locator('x-pw-highlight'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.highlight({ ariaTemplate: `- button "Submit2"` }); | 
					
						
							|  |  |  |   await expect(highlight).toHaveCount(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await backend.highlight({ ariaTemplate: `- button "Submit"` }); | 
					
						
							|  |  |  |   const box1 = roundBox(await button.boundingBox()); | 
					
						
							|  |  |  |   const box2 = roundBox(await highlight.boundingBox()); | 
					
						
							|  |  |  |   expect(box1).toEqual(box2); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-12-13 16:10:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should report error in aria template', async ({ backend }) => { | 
					
						
							|  |  |  |   await backend.navigate({ url: `data:text/html,<button>Submit</button>` }); | 
					
						
							|  |  |  |   const error = await backend.highlight({ ariaTemplate: `- button "Submit` }).catch(e => e); | 
					
						
							|  |  |  |   expect(error.message).toContain('Unterminated string:'); | 
					
						
							|  |  |  | }); |