| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import fs from 'fs'; | 
					
						
							|  |  |  | import path from 'path'; | 
					
						
							|  |  |  | import { test, expect } from './inspectorTest'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should print the correct imports and context options', async ({ runCLI }) => { | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  |   const cli = runCLI(['--target=python-pytest', emptyHTML]); | 
					
						
							| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  |   const expectedResult = `from playwright.sync_api import Page, expect
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_example(page: Page) -> None:`;
 | 
					
						
							|  |  |  |   await cli.waitFor(expectedResult); | 
					
						
							|  |  |  |   expect(cli.text()).toContain(expectedResult); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-04 11:14:53 +01:00
										 |  |  | test('should print the correct context options when using a device and lang', async ({ browserName, runCLI }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  |   test.skip(browserName !== 'webkit'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const tmpFile = testInfo.outputPath('script.js'); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  |   const cli = runCLI(['--target=python-pytest', '--device=iPhone 11', '--lang=en-US', '--output', tmpFile, emptyHTML]); | 
					
						
							| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  |   await cli.exited; | 
					
						
							|  |  |  |   const content = fs.readFileSync(tmpFile); | 
					
						
							|  |  |  |   expect(content.toString()).toBe(`import pytest
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from playwright.sync_api import Page, expect | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(scope="session") | 
					
						
							|  |  |  | def browser_context_args(browser_context_args, playwright): | 
					
						
							| 
									
										
										
										
											2022-05-04 11:14:53 +01:00
										 |  |  |     return {**playwright.devices["iPhone 11"], "locale": "en-US"} | 
					
						
							| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_example(page: Page) -> None: | 
					
						
							|  |  |  |     page.goto("${emptyHTML}") | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should save the codegen output to a file if specified', async ({ runCLI }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-05-04 11:14:53 +01:00
										 |  |  |   const tmpFile = testInfo.outputPath('test_example.py'); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:55:20 -04:00
										 |  |  |   const cli = runCLI(['--target=python-pytest', '--output', tmpFile, emptyHTML]); | 
					
						
							| 
									
										
										
										
											2022-05-04 10:41:20 +02:00
										 |  |  |   await cli.exited; | 
					
						
							|  |  |  |   const content = fs.readFileSync(tmpFile); | 
					
						
							|  |  |  |   expect(content.toString()).toBe(`from playwright.sync_api import Page, expect
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_example(page: Page) -> None: | 
					
						
							|  |  |  |     page.goto("${emptyHTML}") | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  | }); |