| 
									
										
										
										
											2022-04-13 15:13:31 -07: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 { test, expect } from './playwright-test-fixtures'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-03 13:25:56 -08:00
										 |  |  | test('should work with connectOptions', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.js': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         globalSetup: './global-setup', | 
					
						
							|  |  |  |         use: { | 
					
						
							|  |  |  |           connectOptions: { | 
					
						
							|  |  |  |             wsEndpoint: process.env.CONNECT_WS_ENDPOINT, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'global-setup.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { chromium } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |       module.exports = async () => { | 
					
						
							| 
									
										
										
										
											2023-03-31 08:57:07 -07:00
										 |  |  |         process.env.DEBUG = 'pw:browser'; | 
					
						
							|  |  |  |         process.env.PWTEST_SERVER_WS_HEADERS = | 
					
						
							|  |  |  |           'x-playwright-debug-log: a-debug-log-string\\r\\n' + | 
					
						
							|  |  |  |           'x-playwright-attachment: attachment-a=value-a\\r\\n' + | 
					
						
							|  |  |  |           'x-playwright-debug-log: b-debug-log-string\\r\\n' + | 
					
						
							|  |  |  |           'x-playwright-attachment: attachment-b=value-b'; | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |         const server = await chromium.launchServer(); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |         process.env.CONNECT_WS_ENDPOINT = server.wsEndpoint(); | 
					
						
							|  |  |  |         return () => server.close(); | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |       test.use({ locale: 'fr-CH' }); | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>PASS</div>'); | 
					
						
							|  |  |  |         await expect(page.locator('div')).toHaveText('PASS'); | 
					
						
							|  |  |  |         expect(await page.evaluate(() => navigator.language)).toBe('fr-CH'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-03-31 08:57:07 -07:00
										 |  |  |   expect(result.output).toContain('a-debug-log-string'); | 
					
						
							|  |  |  |   expect(result.output).toContain('b-debug-log-string'); | 
					
						
							|  |  |  |   expect(result.results[0].attachments).toEqual([ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'attachment-a', | 
					
						
							|  |  |  |       contentType: 'text/plain', | 
					
						
							|  |  |  |       body: 'dmFsdWUtYQ==' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'attachment-b', | 
					
						
							|  |  |  |       contentType: 'text/plain', | 
					
						
							|  |  |  |       body: 'dmFsdWUtYg==' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should throw with bad connectOptions', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.js': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         use: { | 
					
						
							|  |  |  |           connectOptions: { | 
					
						
							|  |  |  |             wsEndpoint: 'http://does-not-exist-bad-domain.oh-no-should-not-work', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>PASS</div>'); | 
					
						
							|  |  |  |         await expect(page.locator('div')).toHaveText('PASS'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:57:20 -07:00
										 |  |  |   expect(result.output).toContain('browserType.launch:'); | 
					
						
							|  |  |  |   expect(result.output).toContain('does-not-exist-bad-domain'); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should respect connectOptions.timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.js': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         use: { | 
					
						
							|  |  |  |           connectOptions: { | 
					
						
							|  |  |  |             wsEndpoint: 'wss://locahost:5678', | 
					
						
							|  |  |  |             timeout: 1, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:57:20 -07:00
										 |  |  |   expect(result.output).toContain('browserType.launch: Timeout 1ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  | }); |