| 
									
										
										
										
											2021-02-11 17:46:54 -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-05-08 17:45:04 -07:00
										 |  |  | import { test, expect } from './inspectorTest'; | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | import * as url from 'url'; | 
					
						
							| 
									
										
										
										
											2021-08-18 07:27:45 -07:00
										 |  |  | import fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  | test.describe('cli codegen', () => { | 
					
						
							| 
									
										
										
										
											2021-04-30 13:26:13 -07:00
										 |  |  |   test.skip(({ mode }) => mode !== 'default'); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   test('should contain open page', async ({ openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     await recorder.setContentAndWait(``); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', `page.goto`); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |   const page = await context.newPage();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       Page page = context.newPage();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page = context.new_page()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page = await context.new_page()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | var page = await context.NewPageAsync();`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should contain second page', async ({ openRecorder, page }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(``); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     await page.context().newPage(); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'page1'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |   const page1 = await context.newPage();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       Page page1 = context.newPage();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page1 = context.new_page()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page1 = await context.new_page()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | var page1 = await context.NewPageAsync();`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should contain close page', async ({ openRecorder, page }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(``); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     await page.context().newPage(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.page.close(); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'page.close();'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |   await page.close();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       page.close();`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page.close()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     await page.close()`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | await page.CloseAsync();`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should not lead to an error if html gets clicked', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(''); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     await page.context().newPage(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     const errors: any[] = []; | 
					
						
							|  |  |  |     recorder.page.on('pageerror', e => errors.push(e)); | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     await recorder.page.evaluate(() => document.querySelector('body')!.remove()); | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |     await page.dispatchEvent('html', 'mousemove', { detail: 1 }); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.page.close(); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     await recorder.waitForOutput('JavaScript', 'page.close();'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     expect(errors.length).toBe(0); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 16:56:29 -08:00
										 |  |  |   test('should upload a single file', async ({ page, openRecorder, browserName, asset, isLinux }) => { | 
					
						
							| 
									
										
										
										
											2023-04-12 17:37:21 +00:00
										 |  |  |     test.fixme(browserName === 'firefox' && isLinux, 'https://bugzilla.mozilla.org/show_bug.cgi?id=1827551'); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <form> | 
					
						
							|  |  |  |       <input type="file"> | 
					
						
							|  |  |  |     </form> | 
					
						
							|  |  |  |   `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await page.focus('input[type=file]'); | 
					
						
							| 
									
										
										
										
											2021-04-05 15:51:45 -07:00
										 |  |  |     await page.setInputFiles('input[type=file]', asset('file-to-upload.txt')); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await page.click('input[type=file]'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |   await page.getByRole('textbox').setInputFiles('file-to-upload.txt');`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |       page.getByRole(AriaRole.TEXTBOX).setInputFiles(Paths.get("file-to-upload.txt"));`);
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     page.get_by_role("textbox").set_input_files(\"file-to-upload.txt\")`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     await page.get_by_role("textbox").set_input_files(\"file-to-upload.txt\")`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | await page.GetByRole(AriaRole.Textbox).SetInputFilesAsync(new[] { \"file-to-upload.txt\" });`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 16:56:29 -08:00
										 |  |  |   test('should upload multiple files', async ({ page, openRecorder, browserName, asset, isLinux }) => { | 
					
						
							| 
									
										
										
										
											2023-04-12 17:37:21 +00:00
										 |  |  |     test.fixme(browserName === 'firefox' && isLinux, 'https://bugzilla.mozilla.org/show_bug.cgi?id=1827551'); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <form> | 
					
						
							|  |  |  |       <input type="file" multiple> | 
					
						
							|  |  |  |     </form> | 
					
						
							|  |  |  |   `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await page.focus('input[type=file]'); | 
					
						
							| 
									
										
										
										
											2021-04-05 15:51:45 -07:00
										 |  |  |     await page.setInputFiles('input[type=file]', [asset('file-to-upload.txt'), asset('file-to-upload-2.txt')]); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await page.click('input[type=file]'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |   await page.getByRole('textbox').setInputFiles(['file-to-upload.txt', 'file-to-upload-2.txt']);`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |       page.getByRole(AriaRole.TEXTBOX).setInputFiles(new Path[] {Paths.get("file-to-upload.txt"), Paths.get("file-to-upload-2.txt")});`);
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     page.get_by_role("textbox").set_input_files([\"file-to-upload.txt\", \"file-to-upload-2.txt\"]`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     await page.get_by_role("textbox").set_input_files([\"file-to-upload.txt\", \"file-to-upload-2.txt\"]`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | await page.GetByRole(AriaRole.Textbox).SetInputFilesAsync(new[] { \"file-to-upload.txt\", \"file-to-upload-2.txt\" });`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 16:56:29 -08:00
										 |  |  |   test('should clear files', async ({ page, openRecorder, browserName, asset, isLinux }) => { | 
					
						
							| 
									
										
										
										
											2023-04-12 17:37:21 +00:00
										 |  |  |     test.fixme(browserName === 'firefox' && isLinux, 'https://bugzilla.mozilla.org/show_bug.cgi?id=1827551'); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <form> | 
					
						
							|  |  |  |       <input type="file" multiple> | 
					
						
							|  |  |  |     </form> | 
					
						
							|  |  |  |   `);
 | 
					
						
							|  |  |  |     await page.focus('input[type=file]'); | 
					
						
							| 
									
										
										
										
											2021-04-05 15:51:45 -07:00
										 |  |  |     await page.setInputFiles('input[type=file]', asset('file-to-upload.txt')); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await page.setInputFiles('input[type=file]', []); | 
					
						
							|  |  |  |     await page.click('input[type=file]'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |   await page.getByRole('textbox').setInputFiles([]);`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |       page.getByRole(AriaRole.TEXTBOX).setInputFiles(new Path[0]);`);
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     page.get_by_role("textbox").set_input_files([])`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     await page.get_by_role("textbox").set_input_files([])`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | await page.GetByRole(AriaRole.Textbox).SetInputFilesAsync(new[] {  });`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |   test('should download files', async ({ page, openRecorder, server }) => { | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |     server.setRoute('/download', (req, res) => { | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |       const pathName = url.parse(req.url!).path; | 
					
						
							|  |  |  |       if (pathName === '/download') { | 
					
						
							|  |  |  |         res.setHeader('Content-Type', 'application/octet-stream'); | 
					
						
							|  |  |  |         res.setHeader('Content-Disposition', 'attachment; filename=file.txt'); | 
					
						
							|  |  |  |         res.end(`Hello world`); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         res.setHeader('Content-Type', 'text/html; charset=utf-8'); | 
					
						
							|  |  |  |         res.end(''); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |       <a href="${server.PREFIX}/download" download>Download</a> | 
					
						
							|  |  |  |     `, server.PREFIX);
 | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |     await recorder.hoverOverElement('a'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       page.waitForEvent('download'), | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |       page.click('a') | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       page.waitForEvent('download'), | 
					
						
							|  |  |  |       page.click('a') | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'download1Promise'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |   const downloadPromise = page.waitForEvent('download'); | 
					
						
							|  |  |  |   await page.getByRole('link', { name: 'Download' }).click(); | 
					
						
							|  |  |  |   const download = await downloadPromise;`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |   const download1Promise = page.waitForEvent('download'); | 
					
						
							|  |  |  |   await page.getByRole('link', { name: 'Download' }).click(); | 
					
						
							|  |  |  |   const download1 = await download1Promise;`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       Download download = page.waitForDownload(() -> { | 
					
						
							| 
									
										
										
										
											2022-10-10 11:25:56 -08:00
										 |  |  |         page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Download")).click(); | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       });`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |       Download download1 = page.waitForDownload(() -> { | 
					
						
							|  |  |  |         page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Download")).click(); | 
					
						
							|  |  |  |       });`);
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     with page.expect_download() as download_info: | 
					
						
							| 
									
										
										
										
											2022-10-03 16:14:02 -08:00
										 |  |  |         page.get_by_role("link", name="Download").click() | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     download = download_info.value`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |     with page.expect_download() as download1_info: | 
					
						
							|  |  |  |         page.get_by_role("link", name="Download").click() | 
					
						
							|  |  |  |     download1 = download1_info.value`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     async with page.expect_download() as download_info: | 
					
						
							| 
									
										
										
										
											2022-10-03 16:14:02 -08:00
										 |  |  |         await page.get_by_role("link", name="Download").click() | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     download = await download_info.value`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |     async with page.expect_download() as download1_info: | 
					
						
							|  |  |  |         await page.get_by_role("link", name="Download").click() | 
					
						
							|  |  |  |     download1 = await download1_info.value`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | var download = await page.RunAndWaitForDownloadAsync(async () => | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     await page.GetByRole(AriaRole.Link, new() { Name = "Download" }).ClickAsync(); | 
					
						
							|  |  |  | });`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | var download1 = await page.RunAndWaitForDownloadAsync(async () => | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     await page.GetByRole(AriaRole.Link, new() { Name = "Download" }).ClickAsync(); | 
					
						
							|  |  |  | });`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should handle dialogs', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <button onclick="alert()">click me</button> | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  |     await recorder.hoverOverElement('button'); | 
					
						
							|  |  |  |     page.once('dialog', async dialog => { | 
					
						
							|  |  |  |       await dialog.dismiss(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |     await page.click('button'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'once'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   page.once('dialog', dialog => { | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     console.log(\`Dialog message: \${dialog.message()}\`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     dialog.dismiss().catch(() => {}); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-10-03 16:14:02 -08:00
										 |  |  |   await page.getByRole('button', { name: 'click me' }).click();`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  |       page.onceDialog(dialog -> { | 
					
						
							|  |  |  |         System.out.println(String.format("Dialog message: %s", dialog.message())); | 
					
						
							|  |  |  |         dialog.dismiss(); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-10-10 11:25:56 -08:00
										 |  |  |       page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("click me")).click();`);
 | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page.once(\"dialog\", lambda dialog: dialog.dismiss()) | 
					
						
							| 
									
										
										
										
											2022-10-03 16:14:02 -08:00
										 |  |  |     page.get_by_role("button", name="click me").click()`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  |     page.once(\"dialog\", lambda dialog: dialog.dismiss()) | 
					
						
							| 
									
										
										
										
											2022-10-03 16:14:02 -08:00
										 |  |  |     await page.get_by_role("button", name="click me").click()`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect.soft(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | void page_Dialog_EventHandler(object sender, IDialog dialog) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Console.WriteLine($\"Dialog message: {dialog.Message}\"); | 
					
						
							|  |  |  |     dialog.DismissAsync(); | 
					
						
							|  |  |  |     page.Dialog -= page_Dialog_EventHandler; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | page.Dialog += page_Dialog_EventHandler; | 
					
						
							|  |  |  | await page.GetByRole(AriaRole.Button, new() { Name = "click me" }).ClickAsync();`);
 | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |   test('should handle history.postData', async ({ page, openRecorder, server }) => { | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <script> | 
					
						
							|  |  |  |     let seqNum = 0; | 
					
						
							|  |  |  |     function pushState() { | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |       history.pushState({}, 'title', '${server.PREFIX}/#seqNum=' + (++seqNum)); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |     </script>`, server.PREFIX);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     for (let i = 1; i < 3; ++i) { | 
					
						
							|  |  |  |       await page.evaluate('pushState()'); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |       await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/#seqNum=${i}');`); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-29 08:15:12 -07:00
										 |  |  |   test('should record open in a new tab with url', async ({ page, openRecorder, browserName }) => { | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`<a href="about:blank?foo">link</a>`); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |     const locator = await recorder.hoverOverElement('a'); | 
					
						
							|  |  |  |     expect(locator).toBe(`getByRole('link', { name: 'link' })`); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-29 08:15:12 -07:00
										 |  |  |     await page.click('a', { modifiers: ['ControlOrMeta'] }); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     const sources = await recorder.waitForOutput('JavaScript', 'page1'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 16:09:11 -08:00
										 |  |  |     if (browserName !== 'firefox') { | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |       expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   const page1 = await context.newPage(); | 
					
						
							| 
									
										
										
										
											2021-04-21 07:59:38 -07:00
										 |  |  |   await page1.goto('about:blank?foo');`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |       expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2021-04-21 07:59:38 -07:00
										 |  |  |     page1 = await context.new_page() | 
					
						
							|  |  |  |     await page1.goto("about:blank?foo")`);
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |       expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | var page1 = await context.NewPageAsync(); | 
					
						
							|  |  |  | await page1.GotoAsync("about:blank?foo");`);
 | 
					
						
							| 
									
										
										
										
											2022-02-07 16:09:11 -08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |       expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |   const page1Promise = page.waitForEvent('popup'); | 
					
						
							|  |  |  |   await page.getByRole('link', { name: 'link' }).click({ | 
					
						
							| 
									
										
										
										
											2024-04-29 08:15:12 -07:00
										 |  |  |     modifiers: ['ControlOrMeta'] | 
					
						
							| 
									
										
										
										
											2022-12-02 17:33:01 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  |   const page1 = await page1Promise;`);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should not clash pages', async ({ page, openRecorder, browserName }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     const [popup1] = await Promise.all([ | 
					
						
							|  |  |  |       page.context().waitForEvent('page'), | 
					
						
							|  |  |  |       page.evaluate(`window.open('about:blank')`) | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |     await recorder.setPageContentAndWait(popup1, '<input id=name>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const [popup2] = await Promise.all([ | 
					
						
							|  |  |  |       page.context().waitForEvent('page'), | 
					
						
							|  |  |  |       page.evaluate(`window.open('about:blank')`) | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |     await recorder.setPageContentAndWait(popup2, '<input id=name>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await popup1.type('input', 'TextA'); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     await recorder.waitForOutput('JavaScript', 'TextA'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     await popup2.type('input', 'TextB'); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     await recorder.waitForOutput('JavaScript', 'TextB'); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const sources = recorder.sources(); | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`await page1.locator('#name').fill('TextA');`); | 
					
						
							|  |  |  |     expect(sources.get('JavaScript')!.text).toContain(`await page2.locator('#name').fill('TextB');`); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`page1.locator("#name").fill("TextA");`); | 
					
						
							|  |  |  |     expect(sources.get('Java')!.text).toContain(`page2.locator("#name").fill("TextB");`); | 
					
						
							| 
									
										
										
										
											2021-03-03 14:32:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`page1.locator("#name").fill("TextA")`); | 
					
						
							|  |  |  |     expect(sources.get('Python')!.text).toContain(`page2.locator("#name").fill("TextB")`); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`await page1.locator("#name").fill("TextA")`); | 
					
						
							|  |  |  |     expect(sources.get('Python Async')!.text).toContain(`await page2.locator("#name").fill("TextB")`); | 
					
						
							| 
									
										
										
										
											2021-02-16 18:13:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`await page1.Locator("#name").FillAsync("TextA");`); | 
					
						
							|  |  |  |     expect(sources.get('C#')!.text).toContain(`await page2.Locator("#name").FillAsync("TextB");`); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('click should emit events in order', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |       <button id=button> | 
					
						
							|  |  |  |       <script> | 
					
						
							|  |  |  |       button.addEventListener('mousedown', e => console.log(e.type)); | 
					
						
							|  |  |  |       button.addEventListener('mouseup', e => console.log(e.type)); | 
					
						
							|  |  |  |       button.addEventListener('click', e => console.log(e.type)); | 
					
						
							|  |  |  |       </script> | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const messages: any[] = []; | 
					
						
							| 
									
										
										
										
											2021-05-12 22:19:27 +00:00
										 |  |  |     page.on('console', message => { | 
					
						
							|  |  |  |       if (message.type() !== 'error') | 
					
						
							|  |  |  |         messages.push(message.text()); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       page.click('button'), | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  |       recorder.waitForOutput('JavaScript', '.click(') | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     expect(messages).toEqual(['mousedown', 'mouseup', 'click']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |   test('should update hover model on action', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name='updated'"></input>`); | 
					
						
							| 
									
										
										
										
											2022-08-18 20:12:33 +02:00
										 |  |  |     const [models] = await Promise.all([ | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |       recorder.waitForActionPerformed(), | 
					
						
							|  |  |  |       page.click('input') | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     expect(models.hovered).toBe('#checkbox'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-16 11:13:19 -07:00
										 |  |  |   test('should reset hover model on action when element detaches', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await recorder.setContentAndWait(`<input id="checkbox" onclick="document.getElementById('checkbox').remove()">`); | 
					
						
							|  |  |  |     const [models] = await Promise.all([ | 
					
						
							|  |  |  |       recorder.waitForActionPerformed(), | 
					
						
							|  |  |  |       page.click('input') | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |     expect(models.hovered).toBe(null); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:22:23 -07:00
										 |  |  |   test('should update active model on action', async ({ page, openRecorder, browserName, headless }) => { | 
					
						
							| 
									
										
										
										
											2023-01-27 21:52:34 -08:00
										 |  |  |     test.fixme(browserName === 'webkit'); | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name='updated'"></input>`); | 
					
						
							| 
									
										
										
										
											2022-08-18 20:12:33 +02:00
										 |  |  |     const [models] = await Promise.all([ | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |       recorder.waitForActionPerformed(), | 
					
						
							|  |  |  |       page.click('input') | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     expect(models.active).toBe('#checkbox'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-08 20:40:03 +02:00
										 |  |  |   test('should check input with chaining id', async ({ page, openRecorder }) => { | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name = 'updated'"></input>`); | 
					
						
							|  |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       recorder.waitForActionPerformed(), | 
					
						
							|  |  |  |       page.click('input[id=checkbox]') | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |   test('should record navigations after identical pushState', async ({ page, openRecorder, server }) => { | 
					
						
							| 
									
										
										
										
											2021-04-02 11:19:26 -07:00
										 |  |  |     const recorder = await openRecorder(); | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |     server.setRoute('/page2.html', (req, res) => { | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |       res.setHeader('Content-Type', 'text/html; charset=utf-8'); | 
					
						
							|  |  |  |       res.end('Hello world'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     await recorder.setContentAndWait(`
 | 
					
						
							|  |  |  |     <script> | 
					
						
							|  |  |  |     function pushState() { | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |       history.pushState({}, 'title', '${server.PREFIX}'); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |     </script>`, server.PREFIX);
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |     for (let i = 1; i < 3; ++i) | 
					
						
							|  |  |  |       await page.evaluate('pushState()'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |     await page.goto(server.PREFIX + '/page2.html'); | 
					
						
							| 
									
										
										
										
											2021-06-10 16:52:59 -07:00
										 |  |  |     await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/page2.html');`); | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-04-20 18:45:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-18 07:27:45 -07:00
										 |  |  |   test('should --save-trace', async ({ runCLI }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-09-17 15:32:30 +02:00
										 |  |  |     const traceFileName = testInfo.outputPath('trace.zip'); | 
					
						
							| 
									
										
										
										
											2023-04-12 16:37:24 +00:00
										 |  |  |     const cli = runCLI([`--save-trace=${traceFileName}`], { | 
					
						
							|  |  |  |       autoExitWhen: ' ', | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     await cli.waitForCleanExit(); | 
					
						
							| 
									
										
										
										
											2021-08-18 07:27:45 -07:00
										 |  |  |     expect(fs.existsSync(traceFileName)).toBeTruthy(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 00:13:38 +02:00
										 |  |  |   test('should save assets via SIGINT', async ({ runCLI, platform }, testInfo) => { | 
					
						
							|  |  |  |     test.skip(platform === 'win32', 'SIGINT not supported on Windows'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 15:32:30 +02:00
										 |  |  |     const traceFileName = testInfo.outputPath('trace.zip'); | 
					
						
							| 
									
										
										
										
											2022-08-09 00:13:38 +02:00
										 |  |  |     const storageFileName = testInfo.outputPath('auth.json'); | 
					
						
							|  |  |  |     const harFileName = testInfo.outputPath('har.har'); | 
					
						
							| 
									
										
										
										
											2023-04-12 16:37:24 +00:00
										 |  |  |     const cli = runCLI([`--save-trace=${traceFileName}`, `--save-storage=${storageFileName}`, `--save-har=${harFileName}`]); | 
					
						
							| 
									
										
										
										
											2022-08-09 00:13:38 +02:00
										 |  |  |     await cli.waitFor(`import { test, expect } from '@playwright/test'`); | 
					
						
							| 
									
										
										
										
											2023-06-02 21:59:12 +02:00
										 |  |  |     await cli.process.kill('SIGINT'); | 
					
						
							| 
									
										
										
										
											2022-08-09 00:13:38 +02:00
										 |  |  |     const { exitCode } = await cli.process.exited; | 
					
						
							|  |  |  |     expect(exitCode).toBe(130); | 
					
						
							|  |  |  |     expect(fs.existsSync(traceFileName)).toBeTruthy(); | 
					
						
							|  |  |  |     expect(fs.existsSync(storageFileName)).toBeTruthy(); | 
					
						
							|  |  |  |     expect(fs.existsSync(harFileName)).toBeTruthy(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  |   test('should fill tricky characters', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |     const recorder = await openRecorder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 22:38:50 -04:00
										 |  |  |     await recorder.setContentAndWait(`<textarea spellcheck=false id="textarea" name="name" oninput="console.log(textarea.value)"></textarea>`); | 
					
						
							| 
									
										
										
										
											2022-10-24 18:01:48 -04:00
										 |  |  |     const locator = await recorder.focusElement('textarea'); | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     expect(locator).toBe(`locator('#textarea')`); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const [message, sources] = await Promise.all([ | 
					
						
							|  |  |  |       page.waitForEvent('console', msg => msg.type() !== 'error'), | 
					
						
							|  |  |  |       recorder.waitForOutput('JavaScript', 'fill'), | 
					
						
							|  |  |  |       page.fill('textarea', 'Hello\'\"\`\nWorld') | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('JavaScript')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |   await page.locator('#textarea').fill('Hello\\'"\`\\nWorld');`); | 
					
						
							| 
									
										
										
										
											2022-02-04 19:27:45 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Java')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |       page.locator("#textarea").fill("Hello'\\"\`\\nWorld");`); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     page.locator("#textarea").fill(\"Hello'\\"\`\\nWorld\")`); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('Python Async')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2022-11-09 17:22:13 -08:00
										 |  |  |     await page.locator("#textarea").fill(\"Hello'\\"\`\\nWorld\")`); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |     expect(sources.get('C#')!.text).toContain(`
 | 
					
						
							| 
									
										
										
										
											2023-12-15 10:24:26 -08:00
										 |  |  | await page.Locator("#textarea").FillAsync(\"Hello'\\"\`\\nWorld\");`); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:22:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(message.text()).toBe('Hello\'\"\`\nWorld'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 17:46:54 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-04-29 12:04:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should --test-id-attribute', async ({ page, openRecorder }) => { | 
					
						
							|  |  |  |   const recorder = await openRecorder({ testIdAttributeName: 'my-test-id' }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await recorder.setContentAndWait(`<div my-test-id="foo">Hello</div>`); | 
					
						
							|  |  |  |   await page.click('[my-test-id=foo]'); | 
					
						
							|  |  |  |   const sources = await recorder.waitForOutput('JavaScript', `page.getByTestId`); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 09:31:30 -07:00
										 |  |  |   expect.soft(sources.get('JavaScript')!.text).toContain(`await page.getByTestId('foo').click()`); | 
					
						
							|  |  |  |   expect.soft(sources.get('Java')!.text).toContain(`page.getByTestId("foo").click()`); | 
					
						
							|  |  |  |   expect.soft(sources.get('Python')!.text).toContain(`page.get_by_test_id("foo").click()`); | 
					
						
							|  |  |  |   expect.soft(sources.get('Python Async')!.text).toContain(`await page.get_by_test_id("foo").click()`); | 
					
						
							|  |  |  |   expect.soft(sources.get('C#')!.text).toContain(`await page.GetByTestId("foo").ClickAsync();`); | 
					
						
							| 
									
										
										
										
											2023-04-29 12:04:33 -07:00
										 |  |  | }); |