| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2018 Google Inc. All rights reserved. | 
					
						
							|  |  |  |  * Modifications 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. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-19 21:32:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-06 07:08:22 -07:00
										 |  |  | import { test as it, expect } from './pageTest'; | 
					
						
							| 
									
										
										
										
											2021-05-05 19:10:28 -07:00
										 |  |  | import { attachFrame } from '../config/utils'; | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 19:42:52 +01:00
										 |  |  | it('should work @smoke', async ({ page, server }) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-09-18 15:52:14 -07:00
										 |  |  |   const frame1 = await attachFrame(page, 'frame1', server.EMPTY_PAGE); | 
					
						
							|  |  |  |   await attachFrame(page, 'frame2', server.EMPTY_PAGE); | 
					
						
							|  |  |  |   const frame3 = await attachFrame(page, 'frame3', server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   const frame1handle1 = await page.$('#frame1'); | 
					
						
							|  |  |  |   const frame1handle2 = await frame1.frameElement(); | 
					
						
							|  |  |  |   const frame3handle1 = await page.$('#frame3'); | 
					
						
							|  |  |  |   const frame3handle2 = await frame3.frameElement(); | 
					
						
							|  |  |  |   expect(await frame1handle1.evaluate((a, b) => a === b, frame1handle2)).toBe(true); | 
					
						
							|  |  |  |   expect(await frame3handle1.evaluate((a, b) => a === b, frame3handle2)).toBe(true); | 
					
						
							|  |  |  |   expect(await frame1handle1.evaluate((a, b) => a === b, frame3handle1)).toBe(false); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  | it('should work with contentFrame', async ({ page, server }) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-09-18 15:52:14 -07:00
										 |  |  |   const frame = await attachFrame(page, 'frame1', server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   const handle = await frame.frameElement(); | 
					
						
							|  |  |  |   const contentFrame = await handle.contentFrame(); | 
					
						
							|  |  |  |   expect(contentFrame).toBe(frame); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  | it('should work with frameset', async ({ page, server }) => { | 
					
						
							| 
									
										
										
										
											2021-05-08 21:25:12 -07:00
										 |  |  |   await page.goto(server.PREFIX + '/frames/frameset.html'); | 
					
						
							|  |  |  |   const frameElement1 = await page.$('frame'); | 
					
						
							|  |  |  |   const frame = await frameElement1.contentFrame(); | 
					
						
							|  |  |  |   const frameElement2 = await frame.frameElement(); | 
					
						
							|  |  |  |   expect(await frameElement1.evaluate((a, b) => a === b, frameElement2)).toBe(true); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  | it('should throw when detached', async ({ page, server }) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-09-18 15:52:14 -07:00
										 |  |  |   const frame1 = await attachFrame(page, 'frame1', server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-08-03 15:23:53 -07:00
										 |  |  |   await page.$eval('#frame1', e => e.remove()); | 
					
						
							|  |  |  |   const error = await frame1.frameElement().catch(e => e); | 
					
						
							|  |  |  |   expect(error.message).toContain('Frame has been detached.'); | 
					
						
							|  |  |  | }); |