| 
									
										
										
										
											2021-08-09 11:34:52 +03: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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { test as it, expect } from './pageTest'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const vues = { | 
					
						
							|  |  |  |   'vue2': '/reading-list/vue2.html', | 
					
						
							|  |  |  |   'vue3': '/reading-list/vue3.html', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for (const [name, url] of Object.entries(vues)) { | 
					
						
							|  |  |  |   it.describe(name, () => { | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it.beforeEach(async ({ page, server }) => { | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |       await page.goto(server.PREFIX + url); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 19:42:52 +01:00
										 |  |  |     it('should work with single-root elements @smoke', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-list`)).toHaveCount(1); | 
					
						
							|  |  |  |       // count() was not working, see: https://github.com/microsoft/playwright/issues/12887
 | 
					
						
							| 
									
										
										
										
											2022-03-18 20:22:33 -08:00
										 |  |  |       expect(await page.locator(`_vue=book-list`).count()).toBe(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-list`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(3); | 
					
						
							| 
									
										
										
										
											2022-03-18 20:22:33 -08:00
										 |  |  |       expect(await page.locator(`_vue=book-item`).count()).toBe(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(3); | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-list >> _vue=book-item`)).toHaveCount(3); | 
					
						
							| 
									
										
										
										
											2022-03-18 20:22:33 -08:00
										 |  |  |       expect(await page.locator(`_vue=book-list >> _vue=book-item`).count()).toBe(3); | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item >> _vue=book-list`)).toHaveCount(0); | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should work with multi-root elements (fragments)', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |       it.skip(name === 'vue2', 'vue2 does not support fragments'); | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=Root`)).toHaveCount(15); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=app-header`)).toHaveCount(2); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=new-book`)).toHaveCount(2); | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should not crash when there is no match', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=apps`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-li`)).toHaveCount(0); | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should compose', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item >> text=Gatsby`)).toHaveText('The Great Gatsby'); | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should query by props combinations', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name="The Great Gatsby"]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name="the great gatsby" i]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[nested.index = 0]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[nested.nonexisting.index = 0]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[nested.index.nonexisting = 0]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[nested.index.nonexisting = 1]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[nested.value = 4.1]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[enabled = false]`)).toHaveCount(4); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[enabled = true] `)).toHaveCount(5); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[enabled = true][color = "red"]`)).toHaveCount(2); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[enabled = true][color = "red"i][nested.index =  6]`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should exact match by props', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name = "The Great Gatsby"]`)).toHaveText('The Great Gatsby'); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = "The Great Gatsby"]`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2023-10-04 22:56:42 -04:00
										 |  |  |       // case sensitive by default
 | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name = "the great gatsby"]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = "the great gatsby" s]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = "the great gatsby" S]`)).toHaveCount(0); | 
					
						
							| 
									
										
										
										
											2023-10-04 22:56:42 -04:00
										 |  |  |       // case insensitive with flag
 | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name = "the great gatsby" i]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = "the great gatsby" I]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = "  The Great Gatsby  "]`)).toHaveCount(0); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should partially match by props', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |       // Check partial matching
 | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name *= "Gatsby"]`)).toHaveText('The Great Gatsby'); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name *= "Gatsby"]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=[name *= "Gatsby"]`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=book-item[name = "Gatsby"]`)).toHaveCount(0); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should support all string operators', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=color-button[color = "red"]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color |= "red"]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color $= "ed"]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color ^= "gr"]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color ~= "e"]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name ~= "gatsby" i]`)).toHaveCount(1); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name *= " gatsby" i]`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-22 17:00:56 -07:00
										 |  |  |     it('should support regex', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=color-button[color = /red/]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color = /^red$/]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color = /RED/i]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color = /[pqr]ed/]`)).toHaveCount(3); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=color-button[color = /[pq]ed/]`)).toHaveCount(0); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item[name = /gat.by/i]`)).toHaveCount(1); | 
					
						
							| 
									
										
										
										
											2022-03-22 17:00:56 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should support truthy querying', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-06-30 16:00:05 +02:00
										 |  |  |       await expect(page.locator(`_vue=color-button[enabled]`)).toHaveCount(5); | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-08-20 15:05:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should support nested vue trees', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-08-26 13:07:33 +03:00
										 |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(3); | 
					
						
							|  |  |  |       await page.evaluate(() => { | 
					
						
							|  |  |  |         // @ts-ignore
 | 
					
						
							|  |  |  |         mountNestedApp(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(6); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  |     it('should work with multiroot react', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-08-20 15:05:52 +03:00
										 |  |  |       await it.step('mount second root', async () => { | 
					
						
							|  |  |  |         await expect(page.locator(`_vue=book-item`)).toHaveCount(3); | 
					
						
							|  |  |  |         await page.evaluate(() => { | 
					
						
							|  |  |  |           const anotherRoot = document.createElement('div'); | 
					
						
							|  |  |  |           anotherRoot.id = 'root2'; | 
					
						
							|  |  |  |           anotherRoot.append(document.createElement('div')); | 
					
						
							|  |  |  |           document.body.append(anotherRoot); | 
					
						
							|  |  |  |           // @ts-ignore
 | 
					
						
							|  |  |  |           window.mountApp(anotherRoot.querySelector('div')); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         await expect(page.locator(`_vue=book-item`)).toHaveCount(6); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await it.step('add a new book to second root', async () => { | 
					
						
							|  |  |  |         await page.locator('#root2 input').fill('newbook'); | 
					
						
							|  |  |  |         await page.locator('#root2 >> text=new book').click(); | 
					
						
							|  |  |  |         await expect(page.locator('css=#root >> _vue=book-item')).toHaveCount(3); | 
					
						
							|  |  |  |         await expect(page.locator('css=#root2 >> _vue=book-item')).toHaveCount(4); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-12-07 11:23:37 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should work with multiroot vue inside shadow DOM', async ({ page }) => { | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(3); | 
					
						
							|  |  |  |       await page.evaluate(vueName => { | 
					
						
							|  |  |  |         const anotherRoot = document.createElement('div'); | 
					
						
							|  |  |  |         document.body.append(anotherRoot); | 
					
						
							|  |  |  |         const shadowRoot = anotherRoot.attachShadow({ mode: 'open' }); | 
					
						
							|  |  |  |         if (vueName === 'vue2') { | 
					
						
							|  |  |  |           // Vue2 cannot be mounted in shadow root directly.
 | 
					
						
							|  |  |  |           const div = document.createElement('div'); | 
					
						
							|  |  |  |           shadowRoot.append(div); | 
					
						
							|  |  |  |           // @ts-ignore
 | 
					
						
							|  |  |  |           window.mountApp(div); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           // @ts-ignore
 | 
					
						
							|  |  |  |           window.mountApp(shadowRoot); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, name); | 
					
						
							|  |  |  |       await expect(page.locator(`_vue=book-item`)).toHaveCount(6); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-08-09 11:34:52 +03:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |