| 
									
										
										
										
											2021-01-22 18:47:02 -08: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. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-02-05 14:24:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-06 13:57:14 -08:00
										 |  |  | import type { Page } from 'playwright-core'; | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  | import { test as it, expect } from './inspectorTest'; | 
					
						
							| 
									
										
										
										
											2022-07-01 13:57:33 -07:00
										 |  |  | import { waitForTestLog } from '../../config/utils'; | 
					
						
							| 
									
										
										
										
											2021-01-22 18:47:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 18:43:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  | it('should resume when closing inspector', async ({ page, recorderPageGetter, closeRecorder, mode }) => { | 
					
						
							| 
									
										
										
										
											2021-06-04 18:43:54 -07:00
										 |  |  |   it.skip(mode !== 'default'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const scriptPromise = (async () => { | 
					
						
							|  |  |  |     await page.pause(); | 
					
						
							|  |  |  |   })(); | 
					
						
							|  |  |  |   await recorderPageGetter(); | 
					
						
							|  |  |  |   await closeRecorder(); | 
					
						
							|  |  |  |   await scriptPromise; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-07 12:30:10 -07:00
										 |  |  | it('should not reset timeouts', async ({ page, recorderPageGetter, closeRecorder, server }) => { | 
					
						
							|  |  |  |   page.context().setDefaultNavigationTimeout(1000); | 
					
						
							|  |  |  |   page.context().setDefaultTimeout(1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const pausePromise = page.pause(); | 
					
						
							|  |  |  |   await recorderPageGetter(); | 
					
						
							|  |  |  |   await closeRecorder(); | 
					
						
							|  |  |  |   await pausePromise; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   server.setRoute('/empty.html', () => {}); | 
					
						
							|  |  |  |   const error = await page.goto(server.EMPTY_PAGE).catch(e => e); | 
					
						
							|  |  |  |   expect(error.message).toContain('page.goto: Timeout 1000ms exceeded.'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  | it.describe('pause', () => { | 
					
						
							| 
									
										
										
										
											2021-04-30 13:26:13 -07:00
										 |  |  |   it.skip(({ mode }) => mode !== 'default'); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 13:34:01 -07:00
										 |  |  |   it.afterEach(async ({ recorderPageGetter }, testInfo) => { | 
					
						
							|  |  |  |     if (testInfo.status === 'skipped') | 
					
						
							|  |  |  |       return; | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |       const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |       recorderPage.click('[title="Resume (F8)"]').catch(() => {}); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     } catch (e) { | 
					
						
							|  |  |  |       // Some tests close context.
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |   it('should pause and resume the script', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							|  |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should pause and resume the script with keyboard shortcut', async ({ page, recorderPageGetter }) => { | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							|  |  |  |     await recorderPage.keyboard.press('F8'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							| 
									
										
										
										
											2021-02-05 14:24:27 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should resume from console', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-02-05 14:24:27 -08:00
										 |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       page.waitForFunction(() => (window as any).playwright && (window as any).playwright.resume).then(() => { | 
					
						
							|  |  |  |         return page.evaluate('window.playwright.resume()'); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							| 
									
										
										
										
											2021-02-05 14:24:27 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-01-22 18:47:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should pause after a navigation', async ({ page, server, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.goto(server.EMPTY_PAGE); | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							| 
									
										
										
										
											2021-02-05 14:24:27 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-02-12 10:11:30 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should show source', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-11-01 15:04:30 -07:00
										 |  |  |     const source = await recorderPage.textContent('.source-line-paused'); | 
					
						
							| 
									
										
										
										
											2021-02-12 10:11:30 -08:00
										 |  |  |     expect(source).toContain('page.pause()'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should pause on next pause', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause();  // 1
 | 
					
						
							|  |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const source = await recorderPage.textContent('.source-line-paused'); | 
					
						
							|  |  |  |     expect(source).toContain('page.pause();  // 1'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should step', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.click('button'); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const source = await recorderPage.textContent('.source-line-paused'); | 
					
						
							|  |  |  |     expect(source).toContain('page.pause();'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							|  |  |  |     await recorderPage.waitForSelector('.source-line-paused :has-text("page.click")'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							|  |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should step with keyboard shortcut', async ({ page, recorderPageGetter }) => { | 
					
						
							|  |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.click('button'); | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							|  |  |  |     const source = await recorderPage.textContent('.source-line-paused'); | 
					
						
							|  |  |  |     expect(source).toContain('page.pause();'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await recorderPage.keyboard.press('F10'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused :has-text("page.click")'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.isEnabled('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.keyboard.press('F8'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should highlight pointer', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  |     const actionPointPromise = waitForTestLog<{ x: number, y: number }>(page, 'Action point for test: '); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.click('button'); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  |     const { x, y } = await actionPointPromise; | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     const button = await page.waitForSelector('button'); | 
					
						
							|  |  |  |     const box1 = await button.boundingBox(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const x1 = box1.x + box1.width / 2; | 
					
						
							|  |  |  |     const y1 = box1.y + box1.height / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  |     expect(Math.abs(x1 - x) < 2).toBeTruthy(); | 
					
						
							|  |  |  |     expect(Math.abs(y1 - y) < 2).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-13 22:13:51 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							| 
									
										
										
										
											2021-02-12 10:11:30 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should skip input when resuming', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.click('button'); | 
					
						
							|  |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should populate log', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.click('button'); | 
					
						
							|  |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							|  |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							| 
									
										
										
										
											2021-02-19 18:12:33 -08:00
										 |  |  |       'page.pause- XXms', | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |       'page.click(page.locator(\'button\'))- XXms', | 
					
						
							| 
									
										
										
										
											2021-02-19 18:12:33 -08:00
										 |  |  |       'page.pause', | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-16 17:17:24 -08:00
										 |  |  |   it('should hide internal calls', async ({ page, recorderPageGetter, trace }) => { | 
					
						
							|  |  |  |     it.skip(trace === 'on'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.context().tracing.start(); | 
					
						
							|  |  |  |       page.setDefaultTimeout(0); | 
					
						
							|  |  |  |       page.context().setDefaultNavigationTimeout(0); | 
					
						
							|  |  |  |       await page.context().tracing.stop(); | 
					
						
							|  |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-16 17:17:24 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							|  |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							|  |  |  |       'page.pause- XXms', | 
					
						
							|  |  |  |       'tracing.start- XXms', | 
					
						
							|  |  |  |       'tracing.stop- XXms', | 
					
						
							|  |  |  |       'page.pause', | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-16 17:17:24 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-28 16:02:34 -07:00
										 |  |  |   it('should show expect.toHaveText', async ({ page, recorderPageGetter }) => { | 
					
						
							|  |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await expect(page.locator('button')).toHaveText('Submit'); | 
					
						
							| 
									
										
										
										
											2022-11-28 20:50:16 -08:00
										 |  |  |       await expect(page.locator('button')).not.toHaveText('Submit2'); | 
					
						
							| 
									
										
										
										
											2021-09-28 16:02:34 -07:00
										 |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-09-28 16:02:34 -07:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							|  |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							|  |  |  |       'page.pause- XXms', | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |       'expect(page.locator(\'button\')).toHaveText()- XXms', | 
					
						
							| 
									
										
										
										
											2022-11-28 20:50:16 -08:00
										 |  |  |       'expect(page.locator(\'button\')).not.toHaveText()- XXms', | 
					
						
							| 
									
										
										
										
											2021-09-28 16:02:34 -07:00
										 |  |  |       'page.pause', | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-09-28 16:02:34 -07:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should highlight waitForEvent', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await page.setContent('<button onclick="console.log(1)">Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await Promise.all([ | 
					
						
							| 
									
										
										
										
											2021-05-12 22:19:27 +00:00
										 |  |  |         page.waitForEvent('console', msg => msg.type() === 'log' && msg.text() === '1'), | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |         page.click('button'), | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.click")'); | 
					
						
							|  |  |  |     await recorderPage.waitForSelector('.source-line-running:has-text("page.waitForEvent")'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should populate log with waitForEvent', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await page.setContent('<button onclick="console.log(1)">Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await Promise.all([ | 
					
						
							|  |  |  |         page.waitForEvent('console'), | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |         page.getByRole('button', { name: 'Submit' }).click(), | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |       ]); | 
					
						
							|  |  |  |       await page.pause();  // 2
 | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause();  // 2")'); | 
					
						
							|  |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							| 
									
										
										
										
											2021-02-19 18:12:33 -08:00
										 |  |  |       'page.pause- XXms', | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |       'page.waitForEvent(console)', | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |       'page.getByRole(\'button\', { name: \'Submit\' }).click()- XXms', | 
					
						
							| 
									
										
										
										
											2021-02-19 18:12:33 -08:00
										 |  |  |       'page.pause', | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should populate log with error', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     await page.setContent('<button onclick="console.log(1)">Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |       await page.getByRole('button').isChecked(); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     })().catch(e => e); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2023-03-10 16:22:19 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-error-underline'); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							| 
									
										
										
										
											2021-02-19 18:12:33 -08:00
										 |  |  |       'page.pause- XXms', | 
					
						
							| 
									
										
										
										
											2022-10-18 19:39:58 -04:00
										 |  |  |       'page.getByRole(\'button\').isChecked()- XXms', | 
					
						
							| 
									
										
										
										
											2022-11-04 15:19:16 -07:00
										 |  |  |       'waiting for getByRole(\'button\')', | 
					
						
							| 
									
										
										
										
											2021-09-24 20:51:09 -07:00
										 |  |  |       'error: Error: Not a checkbox or radio button', | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     const error = await scriptPromise; | 
					
						
							|  |  |  |     expect(error.message).toContain('Not a checkbox or radio button'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |   it('should populate log with error in waitForEvent', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await Promise.all([ | 
					
						
							| 
									
										
										
										
											2021-09-22 17:09:09 -07:00
										 |  |  |         page.waitForEvent('console', { timeout: 1 }).catch(() => {}), | 
					
						
							|  |  |  |         page.pause(), | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |       ]); | 
					
						
							| 
									
										
										
										
											2021-09-22 17:09:09 -07:00
										 |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-09-22 17:09:09 -07:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause")'); | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-error:has-text("page.waitForEvent")'); | 
					
						
							|  |  |  |     expect(await sanitizeLog(recorderPage)).toEqual([ | 
					
						
							|  |  |  |       'page.pause- XXms', | 
					
						
							|  |  |  |       'page.waitForEvent(console)', | 
					
						
							|  |  |  |       'waiting for event \"console\"', | 
					
						
							| 
									
										
										
										
											2021-12-06 15:42:57 -08:00
										 |  |  |       'error: Timeout 1ms exceeded while waiting for event \"console\"', | 
					
						
							| 
									
										
										
										
											2021-09-22 17:09:09 -07:00
										 |  |  |       'page.pause', | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |   it('should pause on page close', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.close(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.close();")'); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |   it('should pause on context close', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.context().close(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     await recorderPage.waitForSelector('.source-line-paused:has-text("page.context().close();")'); | 
					
						
							| 
									
										
										
										
											2021-09-22 17:09:09 -07:00
										 |  |  |     // Next line can throw because closing context also closes the inspector page.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]').catch(e => {}); | 
					
						
							| 
									
										
										
										
											2021-02-19 09:33:24 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-03-09 07:44:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |   it('should highlight on explore', async ({ page, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2021-03-09 07:44:10 -08:00
										 |  |  |     await page.setContent('<button>Submit</button>'); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2021-04-05 09:18:56 -07:00
										 |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-11-03 09:55:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const box1Promise = waitForTestLog<Box>(page, 'Highlight box for test: '); | 
					
						
							|  |  |  |     await recorderPage.click('.toolbar .CodeMirror'); | 
					
						
							|  |  |  |     await recorderPage.keyboard.type('getByText(\'Submit\')'); | 
					
						
							|  |  |  |     const box1 = await box1Promise; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 07:44:10 -08:00
										 |  |  |     const button = await page.$('text=Submit'); | 
					
						
							|  |  |  |     const box2 = await button.boundingBox(); | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  |     expect(roundBox(box1)).toEqual(roundBox(box2)); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-03-09 07:44:10 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-12-09 17:15:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should not prevent key events', async ({ page, recorderPageGetter }) => { | 
					
						
							|  |  |  |     await page.setContent('<div>Hello</div>'); | 
					
						
							|  |  |  |     await page.evaluate(() => { | 
					
						
							|  |  |  |       (window as any).log = []; | 
					
						
							|  |  |  |       for (const event of ['keydown', 'keyup', 'keypress']) | 
					
						
							|  |  |  |         window.addEventListener(event, e => (window as any).log.push(e.type)); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       await page.keyboard.press('Enter'); | 
					
						
							|  |  |  |       await page.keyboard.press('A'); | 
					
						
							|  |  |  |       await page.keyboard.press('Shift+A'); | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							|  |  |  |     await recorderPage.waitForSelector(`.source-line-paused:has-text("page.pause")`); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-09 17:15:38 -08:00
										 |  |  |     await recorderPage.waitForSelector(`.source-line-paused:has-text("press('Enter')")`); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-09 17:15:38 -08:00
										 |  |  |     await recorderPage.waitForSelector(`.source-line-paused:has-text("press('A')")`); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-09 17:15:38 -08:00
										 |  |  |     await recorderPage.waitForSelector(`.source-line-paused:has-text("press('Shift+A')")`); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							| 
									
										
										
										
											2021-12-09 17:15:38 -08:00
										 |  |  |     await scriptPromise; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const log = await page.evaluate(() => (window as any).log); | 
					
						
							|  |  |  |     expect(log).toEqual([ | 
					
						
							|  |  |  |       'keydown', | 
					
						
							|  |  |  |       'keypress', | 
					
						
							|  |  |  |       'keyup', | 
					
						
							|  |  |  |       'keydown', | 
					
						
							|  |  |  |       'keypress', | 
					
						
							|  |  |  |       'keyup', | 
					
						
							|  |  |  |       'keydown', | 
					
						
							|  |  |  |       'keydown', | 
					
						
							|  |  |  |       'keypress', | 
					
						
							|  |  |  |       'keyup', | 
					
						
							|  |  |  |       'keyup', | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should highlight locators with custom testId', async ({ page, playwright, recorderPageGetter }) => { | 
					
						
							| 
									
										
										
										
											2022-12-02 17:32:29 -08:00
										 |  |  |     await page.setContent('<div data-custom-id=foo id=target>and me</div>'); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |     const scriptPromise = (async () => { | 
					
						
							|  |  |  |       await page.pause(); | 
					
						
							|  |  |  |       playwright.selectors.setTestIdAttribute('data-custom-id'); | 
					
						
							|  |  |  |       await page.getByTestId('foo').click(); | 
					
						
							|  |  |  |     })(); | 
					
						
							|  |  |  |     const recorderPage = await recorderPageGetter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:32:29 -08:00
										 |  |  |     const box1Promise = waitForTestLog<Box>(page, 'Highlight box for test: '); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  |     await recorderPage.click('[title="Step over (F10)"]'); | 
					
						
							| 
									
										
										
										
											2022-12-02 17:32:29 -08:00
										 |  |  |     const box2 = roundBox(await page.locator('#target').boundingBox()); | 
					
						
							|  |  |  |     const box1 = roundBox(await box1Promise); | 
					
						
							|  |  |  |     expect(box1).toEqual(box2); | 
					
						
							| 
									
										
										
										
											2022-11-29 11:43:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     await recorderPage.click('[title="Resume (F8)"]'); | 
					
						
							|  |  |  |     await scriptPromise; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-01-22 18:47:02 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | async function sanitizeLog(recorderPage: Page): Promise<string[]> { | 
					
						
							| 
									
										
										
										
											2021-02-17 22:10:13 -08:00
										 |  |  |   const results = []; | 
					
						
							|  |  |  |   for (const entry of await recorderPage.$$('.call-log-call')) { | 
					
						
							| 
									
										
										
										
											2021-02-20 14:36:19 -08:00
										 |  |  |     const header =  (await (await entry.$('.call-log-call-header')).textContent()).replace(/— [\d.]+(ms|s)/, '- XXms'); | 
					
						
							|  |  |  |     results.push(header.replace(/page\.waitForEvent\(console\).*/, 'page.waitForEvent(console)')); | 
					
						
							|  |  |  |     results.push(...await entry.$$eval('.call-log-message', ee => ee.map(e => { | 
					
						
							|  |  |  |       return (e.classList.contains('error') ? 'error: ' : '') + e.textContent; | 
					
						
							|  |  |  |     }))); | 
					
						
							| 
									
										
										
										
											2021-02-17 22:10:13 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   return results; | 
					
						
							| 
									
										
										
										
											2021-02-15 08:32:13 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Box = { x: number, y: number, width: number, height: number }; | 
					
						
							|  |  |  | function roundBox(box: Box): Box { | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     x: Math.round(box.x * 1000), | 
					
						
							|  |  |  |     y: Math.round(box.y * 1000), | 
					
						
							|  |  |  |     width: Math.round(box.width * 1000), | 
					
						
							|  |  |  |     height: Math.round(box.height * 1000), | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |