| 
									
										
										
										
											2021-12-07 12:32:11 -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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { test as it, expect } from './inspectorTest'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it.skip(({ mode }) => mode !== 'default'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let scriptPromise; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it.beforeEach(async ({ page, recorderPageGetter }) => { | 
					
						
							|  |  |  |   scriptPromise = (async () => { | 
					
						
							|  |  |  |     await page.pause(); | 
					
						
							|  |  |  |   })(); | 
					
						
							|  |  |  |   await recorderPageGetter(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it.afterEach(async ({ recorderPageGetter }) => { | 
					
						
							|  |  |  |   const recorderPage = await recorderPageGetter(); | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |   recorderPage.click('[title="Resume (F8)"]').catch(() => {}); | 
					
						
							| 
									
										
										
										
											2021-12-07 12:32:11 -08:00
										 |  |  |   await scriptPromise; | 
					
						
							| 
									
										
										
										
											2022-07-07 20:25:48 +02:00
										 |  |  |   recorderPage.click('[title="Resume (F8)"]').catch(() => {}); | 
					
						
							| 
									
										
										
										
											2021-12-07 12:32:11 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.$, playwright.$$', async ({ page }) => { | 
					
						
							|  |  |  |   const body = await page.evaluateHandle('playwright.$("body")'); | 
					
						
							| 
									
										
										
										
											2021-12-08 15:44:07 -08:00
										 |  |  |   expect(await body.evaluate<string, HTMLBodyElement>((node: HTMLBodyElement) => node.nodeName)).toBe('BODY'); | 
					
						
							| 
									
										
										
										
											2021-12-07 12:32:11 -08:00
										 |  |  |   const length = await page.evaluate('playwright.$$("body").length'); | 
					
						
							|  |  |  |   expect(length).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.selector', async ({ page }) => { | 
					
						
							|  |  |  |   const length = await page.evaluate('playwright.selector(document.body)'); | 
					
						
							|  |  |  |   expect(length).toBe('body'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.locator.value', async ({ page }) => { | 
					
						
							|  |  |  |   await page.setContent('<div>Hello<div>'); | 
					
						
							| 
									
										
										
										
											2021-12-14 15:37:31 -08:00
										 |  |  |   const handle = await page.evaluateHandle(`playwright.locator('div', { hasText: 'Hello' }).element`); | 
					
						
							| 
									
										
										
										
											2021-12-08 15:44:07 -08:00
										 |  |  |   expect(await handle.evaluate<string, HTMLDivElement>((node: HTMLDivElement) => node.nodeName)).toBe('DIV'); | 
					
						
							| 
									
										
										
										
											2021-12-07 12:32:11 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.locator.values', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-12-14 15:37:31 -08:00
										 |  |  |   await page.setContent('<div>Hello<div>Bar</div></div>'); | 
					
						
							| 
									
										
										
										
											2022-01-21 01:05:37 +01:00
										 |  |  |   expect(await page.evaluate(`playwright.locator('div', { hasText: 'Hello' }).elements.length`)).toBe(1); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { hasText: 'HElLo' }).elements.length`)).toBe(1); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { hasText: /ELL/ }).elements.length`)).toBe(0); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { hasText: /ELL/i }).elements.length`)).toBe(1); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { hasText: /Hello/ }).elements.length`)).toBe(1); | 
					
						
							| 
									
										
										
										
											2021-12-07 12:32:11 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-02-02 16:55:50 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.locator({ has })', async ({ page }) => { | 
					
						
							|  |  |  |   await page.setContent('<div>Hi</div><div><span>Hello</span></div>'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { has: playwright.locator('span') }).element.innerHTML`)).toContain('Hello'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('div', { has: playwright.locator('text=Hello') }).element.innerHTML`)).toContain('span'); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-12-09 15:25:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | it('should support playwright.getBy*', async ({ page }) => { | 
					
						
							|  |  |  |   await page.setContent('<span>Hello</span><span title="world">World</span>'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.getByText('hello').element.innerHTML`)).toContain('Hello'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.getByTitle('world').element.innerHTML`)).toContain('World'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('span').filter({ hasText: 'hello' }).element.innerHTML`)).toContain('Hello'); | 
					
						
							| 
									
										
										
										
											2022-12-15 11:17:59 -08:00
										 |  |  |   expect(await page.evaluate(`playwright.locator('span').first().element.innerHTML`)).toContain('Hello'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('span').last().element.innerHTML`)).toContain('World'); | 
					
						
							|  |  |  |   expect(await page.evaluate(`playwright.locator('span').nth(1).element.innerHTML`)).toContain('World'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it('expected properties on playwright object', async ({ page }) => { | 
					
						
							|  |  |  |   expect(await page.evaluate(`Object.keys(playwright)`)).toEqual([ | 
					
						
							|  |  |  |     '$', | 
					
						
							|  |  |  |     '$$', | 
					
						
							|  |  |  |     'inspect', | 
					
						
							|  |  |  |     'selector', | 
					
						
							|  |  |  |     'generateLocator', | 
					
						
							|  |  |  |     'resume', | 
					
						
							|  |  |  |     'locator', | 
					
						
							|  |  |  |     'getByTestId', | 
					
						
							|  |  |  |     'getByAltText', | 
					
						
							|  |  |  |     'getByLabel', | 
					
						
							|  |  |  |     'getByPlaceholder', | 
					
						
							|  |  |  |     'getByText', | 
					
						
							|  |  |  |     'getByTitle', | 
					
						
							|  |  |  |     'getByRole', | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2022-12-09 15:25:12 -08:00
										 |  |  | }); |