Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: remove _react and _vue= docs (#38972)

Pavel Feldmanfc8e4f3b51c9
diff --git a/docs/src/other-locators.md b/docs/src/other-locators.md
index 0fda4d2590..de3b1eda99 100644
--- a/docs/src/other-locators.md
+++ b/docs/src/other-locators.md
@@ -492,110 +492,6 @@ parent = page.get_by_text("Hello").locator('xpath=..')
var parent = page.GetByText("Hello").Locator("xpath=..");
```
-## React locator
-
-:::note
-React locator is experimental and prefixed with `_`. The functionality might change in future.
-:::
-
-React locator allows finding elements by their component name and property values. The syntax is very similar to [CSS attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all CSS attribute selector operators.
-
-In React locator, component names are transcribed with **CamelCase**.
-
-```js
-await page.locator('_react=BookItem').click();
-```
-```java
-page.locator("_react=BookItem").click();
-```
-```python async
-await page.locator("_react=BookItem").click()
-```
-```python sync
-page.locator("_react=BookItem").click()
-```
-```csharp
-await page.Locator("_react=BookItem").ClickAsync();
-```
-
-More examples:
-
-- match by **component**: `_react=BookItem`
-- match by component and **exact property value**, case-sensitive: `_react=BookItem[author = "Steven King"]`
-- match by property value only, **case-insensitive**: `_react=[author = "steven king" i]`
-- match by component and **truthy property value**: `_react=MyButton[enabled]`
-- match by component and **boolean value**: `_react=MyButton[enabled = false]`
-- match by property **value substring**: `_react=[author *= "King"]`
-- match by component and **multiple properties**: `_react=BookItem[author *= "king" i][year = 1990]`
-- match by **nested** property value: `_react=[some.nested.value = 12]`
-- match by component and property value **prefix**: `_react=BookItem[author ^= "Steven"]`
-- match by component and property value **suffix**: `_react=BookItem[author $= "Steven"]`
-- match by component and **key**: `_react=BookItem[key = '2']`
-- match by property value **regex**: `_react=[author = /Steven(\\s+King)?/i]`
-
-
-To find React element names in a tree use [React DevTools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi).
-
-
-:::note
-React locator supports React 15 and above.
-:::
-
-:::note
-React locator, as well as [React DevTools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi), only work against **unminified** application builds.
-:::
-
-## Vue locator
-
-:::note
-Vue locator is experimental and prefixed with `_`. The functionality might change in future.
-:::
-
-Vue locator allows finding elements by their component name and property values. The syntax is very similar to [CSS attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all CSS attribute selector operators.
-
-In Vue locator, component names are transcribed with **kebab-case**.
-
-```js
-await page.locator('_vue=book-item').click();
-```
-```java
-page.locator("_vue=book-item").click();
-```
-```python async
-await page.locator("_vue=book-item").click()
-```
-```python sync
-page.locator("_vue=book-item").click()
-```
-```csharp
-await page.Locator("_vue=book-item").ClickAsync();
-```
-
-More examples:
-
-- match by **component**: `_vue=book-item`
-- match by component and **exact property value**, case-sensitive: `_vue=book-item[author = "Steven King"]`
-- match by property value only, **case-insensitive**: `_vue=[author = "steven king" i]`
-- match by component and **truthy property value**: `_vue=my-button[enabled]`
-- match by component and **boolean value**: `_vue=my-button[enabled = false]`
-- match by property **value substring**: `_vue=[author *= "King"]`
-- match by component and **multiple properties**: `_vue=book-item[author *= "king" i][year = 1990]`
-- match by **nested** property value: `_vue=[some.nested.value = 12]`
-- match by component and property value **prefix**: `_vue=book-item[author ^= "Steven"]`
-- match by component and property value **suffix**: `_vue=book-item[author $= "Steven"]`
-- match by property value **regex**: `_vue=[author = /Steven(\\s+King)?/i]`
-
-To find Vue element names in a tree use [Vue DevTools](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en).
-
-:::note
-Vue locator supports Vue2 and above.
-:::
-
-:::note
-Vue locator, as well as [Vue DevTools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi), only work against **unminified** application builds.
-:::
-
-
## XPath locator
:::warning
diff --git a/docs/src/release-notes-csharp.md b/docs/src/release-notes-csharp.md
index d41f932f71..8a9c576fc2 100644
--- a/docs/src/release-notes-csharp.md
+++ b/docs/src/release-notes-csharp.md
@@ -1689,7 +1689,7 @@ await locator.ClickAsync();
Learn more in the [documentation](./api/class-locator).
-#### 🧩 Experimental [**React**](./other-locators.md#react-locator) and [**Vue**](./other-locators.md#vue-locator) selector engines
+#### 🧩 Experimental [**React**](./other-locators.md) and [**Vue**](./other-locators.md) selector engines
React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all attribute selector operators.
@@ -1698,7 +1698,7 @@ await page.Locator("_react=SubmitButton[enabled=true]").ClickAsync();
await page.Locator("_vue=submit-button[enabled=true]").ClickAsync();
```
-Learn more in the [react selectors documentation](./other-locators.md#react-locator) and the [vue selectors documentation](./other-locators.md#vue-locator).
+Learn more in the [react selectors documentation](./other-locators.md) and the [vue selectors documentation](./other-locators.md).
#### ✨ New [**`nth`**](./other-locators.md#n-th-element-locator) and [**`visible`**](./other-locators.md#css-matching-only-visible-elements) selector engines
diff --git a/docs/src/release-notes-java.md b/docs/src/release-notes-java.md
index 5081bef05f..5d619d6afb 100644
--- a/docs/src/release-notes-java.md
+++ b/docs/src/release-notes-java.md
@@ -1707,7 +1707,7 @@ locator.click();
Learn more in the [documentation](./api/class-locator).
-#### 🧩 Experimental [**React**](./other-locators.md#react-locator) and [**Vue**](./other-locators.md#vue-locator) selector engines
+#### 🧩 Experimental [**React**](./other-locators.md) and [**Vue**](./other-locators.md) selector engines
React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all attribute selector operators.
@@ -1716,7 +1716,7 @@ page.locator("_react=SubmitButton[enabled=true]").click();
page.locator("_vue=submit-button[enabled=true]").click();
```
-Learn more in the [react selectors documentation](./other-locators.md#react-locator) and the [vue selectors documentation](./other-locators.md#vue-locator).
+Learn more in the [react selectors documentation](./other-locators.md) and the [vue selectors documentation](./other-locators.md).
#### ✨ New [**`nth`**](./other-locators.md#n-th-element-locator) and [**`visible`**](./other-locators.md#css-matching-only-visible-elements) selector engines
diff --git a/docs/src/release-notes-js.md b/docs/src/release-notes-js.md
index 000f5c3d4b..da1add5293 100644
--- a/docs/src/release-notes-js.md
+++ b/docs/src/release-notes-js.md
@@ -3140,7 +3140,7 @@ await locator.click();
Learn more in the [documentation](./api/class-locator).
-#### 🧩 Experimental [**React**](./other-locators.md#react-locator) and [**Vue**](./other-locators.md#vue-locator) selector engines
+#### 🧩 Experimental [**React**](./other-locators.md) and [**Vue**](./other-locators.md) selector engines
React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all attribute selector operators.
@@ -3149,7 +3149,7 @@ await page.locator('_react=SubmitButton[enabled=true]').click();
await page.locator('_vue=submit-button[enabled=true]').click();
```
-Learn more in the [react selectors documentation](./other-locators.md#react-locator) and the [vue selectors documentation](./other-locators.md#vue-locator).
+Learn more in the [react selectors documentation](./other-locators.md) and the [vue selectors documentation](./other-locators.md).
#### ✨ New [**`nth`**](./other-locators.md#n-th-element-locator) and [**`visible`**](./other-locators.md#css-matching-only-visible-elements) selector engines
diff --git a/docs/src/release-notes-python.md b/docs/src/release-notes-python.md
index ae51bad271..1dcee0b26d 100644
--- a/docs/src/release-notes-python.md
+++ b/docs/src/release-notes-python.md
@@ -1696,7 +1696,7 @@ locator.click()
Learn more in the [documentation](./api/class-locator).
-#### 🧩 Experimental [**React**](./other-locators.md#react-locator) and [**Vue**](./other-locators.md#vue-locator) selector engines
+#### 🧩 Experimental [**React**](./other-locators.md) and [**Vue**](./other-locators.md) selector engines
React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all attribute selector operators.
@@ -1705,7 +1705,7 @@ page.locator("_react=SubmitButton[enabled=true]").click()
page.locator("_vue=submit-button[enabled=true]").click()
```
-Learn more in the [react selectors documentation](./other-locators.md#react-locator) and the [vue selectors documentation](./other-locators.md#vue-locator).
+Learn more in the [react selectors documentation](./other-locators.md) and the [vue selectors documentation](./other-locators.md).
#### ✨ New [**`nth`**](./other-locators.md#n-th-element-locator) and [**`visible`**](./other-locators.md#css-matching-only-visible-elements) selector engines
diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.ts
index 2be0082e4d..c0ac914bb2 100644
--- a/packages/injected/src/injectedScript.ts
+++ b/packages/injected/src/injectedScript.ts
@@ -23,13 +23,11 @@ import { generateAriaTree, getAllElementsMatchingExpectAriaTemplate, matchesExpe
import { beginDOMCaches, enclosingShadowRootOrDocument, endDOMCaches, isElementVisible, isInsideScope, parentElementOrShadowHost, setGlobalOptions } from './domUtils';
import { Highlight } from './highlight';
import { kLayoutSelectorNames, layoutSelectorScore } from './layoutSelectorUtils';
-import { createReactEngine } from './reactSelectorEngine';
import { createRoleEngine } from './roleSelectorEngine';
import { beginAriaCaches, endAriaCaches, getAriaDisabled, getAriaRole, getCheckedAllowMixed, getCheckedWithoutMixed, getElementAccessibleDescription, getElementAccessibleErrorMessage, getElementAccessibleName, getReadonly } from './roleUtils';
import { SelectorEvaluatorImpl, sortInDOMOrder } from './selectorEvaluator';
import { generateSelector } from './selectorGenerator';
import { elementMatchesText, elementText, getElementLabels } from './selectorUtils';
-import { createVueEngine } from './vueSelectorEngine';
import { XPathEngine } from './xpathSelectorEngine';
import { ConsoleAPI } from './consoleApi';
import { UtilityScript } from './utilityScript';
@@ -204,8 +202,6 @@ export class InjectedScript {
this._engines = new Map();
this._engines.set('xpath', XPathEngine);
this._engines.set('xpath:light', XPathEngine);
- this._engines.set('_react', createReactEngine());
- this._engines.set('_vue', createVueEngine());
this._engines.set('role', createRoleEngine(false));
this._engines.set('text', this._createTextEngine(true, false));
this._engines.set('text:light', this._createTextEngine(false, false));
diff --git a/packages/injected/src/reactSelectorEngine.ts b/packages/injected/src/reactSelectorEngine.ts
deleted file mode 100644
index eb27da6947..0000000000
--- a/packages/injected/src/reactSelectorEngine.ts
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * 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 { parseAttributeSelector } from '@isomorphic/selectorParser';
-
-import { isInsideScope } from './domUtils';
-import { matchesComponentAttribute } from './selectorUtils';
-
-import type { SelectorEngine, SelectorRoot } from './selectorEngine';
-
-type ComponentNode = {
- key?: any,
- name: string,
- children: ComponentNode[],
- rootElements: Element[],
- props: any,
-};
-
-type ReactVNode = {
- key?: any,
- // React 16+
- type: any,
- child?: ReactVNode,
- sibling?: ReactVNode,
- stateNode?: Node,
- memoizedProps?: any,
-
- // React 15
- _hostNode?: any,
- _currentElement?: any,
- _renderedComponent?: any,
- _renderedChildren?: any[],
-};
-
-function getFunctionComponentName(component: any) {
- return component.displayName || component.name || 'Anonymous';
-}
-
-function getComponentName(reactElement: ReactVNode): string {
- // React 16+
- // @see https://github.com/baruchvlz/resq/blob/5c15a5e04d3f7174087248f5a158c3d6dcc1ec72/src/utils.js#L16
- if (reactElement.type) {
- switch (typeof reactElement.type) {
- case 'function':
- return getFunctionComponentName(reactElement.type);
- case 'string':
- return reactElement.type;
- case 'object': // support memo and forwardRef
- return reactElement.type.displayName || (reactElement.type.render ? getFunctionComponentName(reactElement.type.render) : '');
- }
- }
-
- // React 15
- // @see https://github.com/facebook/react/blob/2edf449803378b5c58168727d4f123de3ba5d37f/packages/react-devtools-shared/src/backend/legacy/renderer.js#L59
- if (reactElement._currentElement) {
- const elementType = reactElement._currentElement.type;
- if (typeof elementType === 'string')
- return elementType;
- if (typeof elementType === 'function')
- return elementType.displayName || elementType.name || 'Anonymous';
- }
- return '';
-}
-
-function getComponentKey(reactElement: ReactVNode): any {
- return reactElement.key ?? reactElement._currentElement?.key;
-}
-
-function getChildren(reactElement: ReactVNode): ReactVNode[] {
- // React 16+
- // @see https://github.com/baruchvlz/resq/blob/5c15a5e04d3f7174087248f5a158c3d6dcc1ec72/src/utils.js#L192
- if (reactElement.child) {
- const children: ReactVNode[] = [];
- for (let child: ReactVNode|undefined = reactElement.child; child; child = child.sibling)
- children.push(child);
- return children;
- }
-
- // React 15
- // @see https://github.com/facebook/react/blob/2edf449803378b5c58168727d4f123de3ba5d37f/packages/react-devtools-shared/src/backend/legacy/renderer.js#L101
- if (!reactElement._currentElement)
- return [];
- const isKnownElement = (reactElement: ReactVNode) => {
- const elementType = reactElement._currentElement?.type;
- return typeof elementType === 'function' || typeof elementType === 'string';
- };
-
- if (reactElement._renderedComponent) {
- const child = reactElement._renderedComponent;
- return isKnownElement(child) ? [child] : [];
- }
- if (reactElement._renderedChildren)
- return [...Object.values(reactElement._renderedChildren)].filter(isKnownElement);
- return [];
-}
-
-function getProps(reactElement: ReactVNode) {
- const props = /* React 16+ */ reactElement.memoizedProps || /* React 15 */ reactElement._currentElement?.props;
- if (!props || typeof props === 'string')
- return props;
- const result = { ...props };
-
- delete result.children;
- return result;
-}
-
-function buildComponentsTree(reactElement: ReactVNode): ComponentNode {
- const treeNode: ComponentNode = {
- key: getComponentKey(reactElement),
- name: getComponentName(reactElement),
- children: getChildren(reactElement).map(buildComponentsTree),
- rootElements: [],
- props: getProps(reactElement),
- };
-
- // @see https://github.com/baruchvlz/resq/blob/5c15a5e04d3f7174087248f5a158c3d6dcc1ec72/src/utils.js#L29
- const rootElement = /* React 16+ */ reactElement.stateNode || /* React 15 */ reactElement._hostNode || /* React 15 */ reactElement._renderedComponent?._hostNode;
- if (rootElement instanceof Element) {
- treeNode.rootElements.push(rootElement);
- } else {
- for (const child of treeNode.children)
- treeNode.rootElements.push(...child.rootElements);
- }
- return treeNode;
-}
-
-function filterComponentsTree(treeNode: ComponentNode, searchFn: (node: ComponentNode) => boolean, result: ComponentNode[] = []) {
- if (searchFn(treeNode))
- result.push(treeNode);
- for (const child of treeNode.children)
- filterComponentsTree(child, searchFn, result);
- return result;
-}
-
-function findReactRoots(root: Document | ShadowRoot, roots: ReactVNode[] = []): ReactVNode[] {
- const document = root.ownerDocument || root;
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
- do {
- const node = walker.currentNode;
-
- const reactNode = node as { readonly [customKey: string]: any };
- // React 17+
- // React sets rootKey when mounting
- // @see https://github.com/facebook/react/blob/a724a3b578dce77d427bef313102a4d0e978d9b4/packages/react-dom/src/client/ReactDOMComponentTree.js#L62-L64
- const rootKey = Object.keys(reactNode).find(key => key.startsWith('__reactContainer') && reactNode[key] !== null);
- if (rootKey) {
- roots.push(reactNode[rootKey].stateNode.current);
- } else {
- const legacyRootKey = '_reactRootContainer';
- if (reactNode.hasOwnProperty(legacyRootKey) && reactNode[legacyRootKey] !== null) {
- // ReactDOM Legacy client API:
- // @see https://github.com/baruchvlz/resq/blob/5c15a5e04d3f7174087248f5a158c3d6dcc1ec72/src/utils.js#L329
- roots.push(reactNode[legacyRootKey]._internalRoot.current);
- }
- }
-
- // Pre-react 16: rely on `data-reactroot`
- // @see https://github.com/facebook/react/issues/10971
- if ((node instanceof Element) && node.hasAttribute('data-reactroot')) {
- for (const key of Object.keys(node)) {
- // @see https://github.com/baruchvlz/resq/blob/5c15a5e04d3f7174087248f5a158c3d6dcc1ec72/src/utils.js#L334
- if (key.startsWith('__reactInternalInstance') || key.startsWith('__reactFiber'))
- roots.push((node as any)[key]);
- }
- }
-
- const shadowRoot = node instanceof Element ? node.shadowRoot : null;
- if (shadowRoot)
- findReactRoots(shadowRoot, roots);
- } while (walker.nextNode());
- return roots;
-}
-
-export const createReactEngine = (): SelectorEngine => ({
- queryAll(scope: SelectorRoot, selector: string): Element[] {
- const { name, attributes } = parseAttributeSelector(selector, false);
-
- const reactRoots = findReactRoots(scope.ownerDocument || scope);
- const trees = reactRoots.map(reactRoot => buildComponentsTree(reactRoot));
- const treeNodes = trees.map(tree => filterComponentsTree(tree, treeNode => {
- const props = treeNode.props ?? {};
-
- if (treeNode.key !== undefined)
- props.key = treeNode.key;
-
- if (name && treeNode.name !== name)
- return false;
- if (treeNode.rootElements.some(domNode => !isInsideScope(scope, domNode)))
- return false;
- for (const attr of attributes) {
- if (!matchesComponentAttribute(props, attr))
- return false;
- }
- return true;
- })).flat();
- const allRootElements: Set<Element> = new Set();
- for (const treeNode of treeNodes) {
- for (const domNode of treeNode.rootElements)
- allRootElements.add(domNode);
- }
- return [...allRootElements];
- }
-});
diff --git a/packages/injected/src/vueSelectorEngine.ts b/packages/injected/src/vueSelectorEngine.ts
deleted file mode 100644
index 287b04568c..0000000000
--- a/packages/injected/src/vueSelectorEngine.ts
+++ /dev/null
@@ -1,268 +0,0 @@
-/**
- * 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 { parseAttributeSelector } from '@isomorphic/selectorParser';
-
-import { isInsideScope } from './domUtils';
-import { matchesComponentAttribute } from './selectorUtils';
-
-import type { SelectorEngine, SelectorRoot } from './selectorEngine';
-
-type ComponentNode = {
- name: string,
- children: ComponentNode[],
- rootElements: Element[],
- props: any,
-};
-
-type VueVNode = {
- // Vue3
- type: any,
- root?: any,
- parent?: VueVNode,
- appContext?: any,
- _isBeingDestroyed?: any,
- isUnmounted?: any,
- subTree: any,
- props: any,
-
- // Vue2
- $children?: VueVNode[],
- fnOptions?: any,
- $options?: any,
- $root?: VueVNode,
- $el?: Element,
- _props: any,
-};
-
-// @see https://github.com/vuejs/devtools/blob/14085e25313bcf8ffcb55f9092a40bc0fe3ac11c/packages/shared-utils/src/util.ts#L295
-function basename(filename: string, ext: string): string {
- const normalized = filename.replace(/^[a-zA-Z]:/, '').replace(/\\/g, '/');
- let result = normalized.substring(normalized.lastIndexOf('/') + 1);
- if (ext && result.endsWith(ext))
- result = result.substring(0, result.length - ext.length);
- return result;
-}
-
-// @see https://github.com/vuejs/devtools/blob/14085e25313bcf8ffcb55f9092a40bc0fe3ac11c/packages/shared-utils/src/util.ts#L41
-function toUpper(_: any, c: string): string {
- return c ? c.toUpperCase() : '';
-}
-
-// @see https://github.com/vuejs/devtools/blob/14085e25313bcf8ffcb55f9092a40bc0fe3ac11c/packages/shared-utils/src/util.ts#L23
-const classifyRE = /(?:^|[-_/])(\w)/g;
-const classify = (str: string) => {
- return str && str.replace(classifyRE, toUpper);
-};
-
-function buildComponentsTreeVue3(instance: VueVNode): ComponentNode {
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L47
- function getComponentTypeName(options: any): string|undefined {
- const name = options.name || options._componentTag || options.__playwright_guessedName;
- if (name)
- return name;
- const file = options.__file; // injected by vue-loader
- if (file)
- return classify(basename(file, '.vue'));
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L42
- function saveComponentName(instance: VueVNode, key: string): string {
- instance.type.__playwright_guessedName = key;
- return key;
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L29
- function getInstanceName(instance: VueVNode): string {
- const name = getComponentTypeName(instance.type || {});
- if (name)
- return name;
- if (instance.root === instance)
- return 'Root';
- for (const key in instance.parent?.type?.components) {
- if (instance.parent?.type.components[key] === instance.type)
- return saveComponentName(instance, key);
- }
- for (const key in instance.appContext?.components) {
- if (instance.appContext.components[key] === instance.type)
- return saveComponentName(instance, key);
- }
- return 'Anonymous Component';
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L6
- function isBeingDestroyed(instance: VueVNode): boolean {
- return instance._isBeingDestroyed || instance.isUnmounted;
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L16
- function isFragment(instance: VueVNode): boolean {
- return instance.subTree.type.toString() === 'Symbol(Fragment)';
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/tree.ts#L79
- function getInternalInstanceChildren(subTree: any): VueVNode[] {
- const list = [];
- if (subTree.component)
- list.push(subTree.component);
- if (subTree.suspense)
- list.push(...getInternalInstanceChildren(subTree.suspense.activeBranch));
- if (Array.isArray(subTree.children)) {
- subTree.children.forEach((childSubTree: any) => {
- if (childSubTree.component)
- list.push(childSubTree.component);
- else
- list.push(...getInternalInstanceChildren(childSubTree));
- });
- }
- return list.filter(child => !isBeingDestroyed(child) && !child.type.devtools?.hide);
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/el.ts#L8
- function getRootElementsFromComponentInstance(instance: VueVNode): Element[] {
- if (isFragment(instance))
- return getFragmentRootElements(instance.subTree);
- return [instance.subTree.el];
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/el.ts#L15
- function getFragmentRootElements(vnode: any): Element[] {
- if (!vnode.children)
- return [];
-
- const list = [];
-
- for (let i = 0, l = vnode.children.length; i < l; i++) {
- const childVnode = vnode.children[i];
- if (childVnode.component)
- list.push(...getRootElementsFromComponentInstance(childVnode.component));
- else if (childVnode.el)
- list.push(childVnode.el);
- }
- return list;
- }
-
- function buildComponentsTree(instance: VueVNode): ComponentNode {
- return {
- name: getInstanceName(instance),
- children: getInternalInstanceChildren(instance.subTree).map(buildComponentsTree),
- rootElements: getRootElementsFromComponentInstance(instance),
- props: instance.props,
- };
- }
-
- return buildComponentsTree(instance);
-}
-
-function buildComponentsTreeVue2(instance: VueVNode): ComponentNode {
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/shared-utils/src/util.ts#L302
- function getComponentName(options: any): string|undefined {
- const name = options.displayName || options.name || options._componentTag;
- if (name)
- return name;
- const file = options.__file; // injected by vue-loader
- if (file)
- return classify(basename(file, '.vue'));
- }
-
- // @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue2/src/components/util.ts#L10
- function getInstanceName(instance: VueVNode): string {
- const name = getComponentName(instance.$options || instance.fnOptions || {});
- if (name)
- return name;
- return instance.$root === instance ? 'Root' : 'Anonymous Component';
- }
-
- // @see https://github.com/vuejs/devtools/blob/14085e25313bcf8ffcb55f9092a40bc0fe3ac11c/packages/app-backend-vue2/src/components/tree.ts#L103
- function getInternalInstanceChildren(instance: VueVNode): VueVNode[] {
- if (instance.$children)
- return instance.$children;
- if (Array.isArray(instance.subTree.children))
- return instance.subTree.children.filter((vnode: any) => !!vnode.component).map((vnode: any) => vnode.component);
- return [];
- }
-
- function buildComponentsTree(instance: VueVNode): ComponentNode {
- return {
- name: getInstanceName(instance),
- children: getInternalInstanceChildren(instance).map(buildComponentsTree),
- rootElements: [instance.$el!],
- props: instance._props,
- };
- }
-
- return buildComponentsTree(instance);
-}
-
-function filterComponentsTree(treeNode: ComponentNode, searchFn: (node: ComponentNode) => boolean, result: ComponentNode[] = []): ComponentNode[] {
- if (searchFn(treeNode))
- result.push(treeNode);
- for (const child of treeNode.children)
- filterComponentsTree(child, searchFn, result);
- return result;
-}
-
-type VueRoot = {version: number, root: VueVNode};
-function findVueRoots(root: Document | ShadowRoot, roots: VueRoot[] = []): VueRoot[] {
- const document = root.ownerDocument || root;
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
- // Vue2 roots are referred to from elements.
- const vue2Roots = new Set<VueVNode>();
- do {
- const node = walker.currentNode;
- if ((node as any).__vue__)
- vue2Roots.add((node as any).__vue__.$root);
- // Vue3 roots are marked with __vue_app__.
- if ((node as any).__vue_app__ && (node as any)._vnode && (node as any)._vnode.component)
- roots.push({ root: (node as any)._vnode.component, version: 3 });
- const shadowRoot = node instanceof Element ? node.shadowRoot : null;
- if (shadowRoot)
- findVueRoots(shadowRoot, roots);
- } while (walker.nextNode());
- for (const vue2root of vue2Roots) {
- roots.push({
- version: 2,
- root: vue2root,
- });
- }
- return roots;
-}
-
-export const createVueEngine = (): SelectorEngine => ({
- queryAll(scope: SelectorRoot, selector: string): Element[] {
- const document = scope.ownerDocument || scope;
- const { name, attributes } = parseAttributeSelector(selector, false);
- const vueRoots = findVueRoots(document);
- const trees = vueRoots.map(vueRoot => vueRoot.version === 3 ? buildComponentsTreeVue3(vueRoot.root) : buildComponentsTreeVue2(vueRoot.root));
- const treeNodes = trees.map(tree => filterComponentsTree(tree, treeNode => {
- if (name && treeNode.name !== name)
- return false;
- if (treeNode.rootElements.some(rootElement => !isInsideScope(scope, rootElement)))
- return false;
- for (const attr of attributes) {
- if (!matchesComponentAttribute(treeNode.props, attr))
- return false;
- }
- return true;
- })).flat();
- const allRootElements = new Set<Element>();
- for (const treeNode of treeNodes) {
- for (const rootElement of treeNode.rootElements)
- allRootElements.add(rootElement);
- }
- return [...allRootElements];
- }
-});
diff --git a/tests/page/selectors-react.spec.ts b/tests/page/selectors-react.spec.ts
deleted file mode 100644
index d9e998fb7b..0000000000
--- a/tests/page/selectors-react.spec.ts
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * 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 as baseExpect } from './pageTest';
-import type { Locator } from 'playwright-core';
-
-const expect = baseExpect.extend({
- async toHaveCountError(locator: Locator, expected: number) {
- try {
- await expect(locator).toHaveCount(expected);
- if (!expected)
- return { pass: true, message: () => 'Locator has expected count of 0' };
- return {
- pass: false,
- message: () => `Querying locator ${locator.toString()} should throw, but it did not.`,
- };
- } catch (e) {
- const message = (e as Error).message;
- try {
- expect(message).toContain(`"_react" selector is not supported`);
- expect(message).toContain(`resolved to ${expected} element`);
- } catch (error) {
- return { pass: false, message: () => (error as Error).message };
- }
- return { pass: true, message: () => 'Error message is as expected' };
- }
- }
-});
-
-const reacts = {
- 'react15': '/reading-list/react15.html',
- 'react16': '/reading-list/react16.html',
- 'react17': '/reading-list/react17.html',
- 'react18': '/reading-list/react18.html',
-};
-
-for (const [name, url] of Object.entries(reacts)) {
- it.describe(name, () => {
- it.beforeEach(async ({ page, server }) => {
- await page.goto(server.PREFIX + url);
- });
-
- it('should work with single-root elements @smoke', async ({ page }) => {
- await expect(page.locator(`_react=BookList`)).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
- await expect(page.locator(`_react=BookList >> _react=BookItem`)).toHaveCountError(3);
- await expect(page.locator(`_react=BookItem >> _react=BookList`)).toHaveCountError(0);
- });
-
- it('should work with multi-root elements (fragments)', async ({ page }) => {
- it.skip(name === 'react15', 'React 15 does not support fragments');
- await expect(page.locator(`_react=App`)).toHaveCountError(15);
- await expect(page.locator(`_react=AppHeader`)).toHaveCountError(2);
- await expect(page.locator(`_react=NewBook`)).toHaveCountError(2);
- });
-
- it('should not crash when there is no match', async ({ page }) => {
- await expect(page.locator(`_react=Apps`)).toHaveCountError(0);
- await expect(page.locator(`_react=BookLi`)).toHaveCountError(0);
- });
-
- it('should compose', async ({ page }) => {
- await expect(page.locator(`_react=NewBook >> _react=button`).locator(':scope:has-text("new book")')).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem >> text=Gatsby`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- });
-
- it('should query by props combinations', async ({ page }) => {
- await expect(page.locator(`_react=BookItem[name="The Great Gatsby"]`)).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name="the great gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_react=li[key="The Great Gatsby"]`)).toHaveCountError(1);
- await expect(page.locator(`_react=ColorButton[nested.index = 0]`)).toHaveCountError(1);
- await expect(page.locator(`_react=ColorButton[nested.nonexisting.index = 0]`)).toHaveCountError(0);
- await expect(page.locator(`_react=ColorButton[nested.index.nonexisting = 0]`)).toHaveCountError(0);
- await expect(page.locator(`_react=ColorButton[nested.index.nonexisting = 1]`)).toHaveCountError(0);
- await expect(page.locator(`_react=ColorButton[nested.value = 4.1]`)).toHaveCountError(1);
- await expect(page.locator(`_react=ColorButton[enabled = false]`)).toHaveCountError(4);
- await expect(page.locator(`_react=ColorButton[enabled = true] `)).toHaveCountError(5);
- await expect(page.locator(`_react=ColorButton[enabled = true][color = "red"]`)).toHaveCountError(2);
- await expect(page.locator(`_react=ColorButton[enabled = true][color = "red"i][nested.index = 6]`)).toHaveCountError(1);
- });
-
- it('should exact match by props', async ({ page }) => {
- await expect(page.locator(`_react=BookItem[name = "The Great Gatsby"]`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name = "The Great Gatsby"]`)).toHaveCountError(1);
- // case sensitive by default
- await expect(page.locator(`_react=BookItem[name = "the great gatsby"]`)).toHaveCountError(0);
- await expect(page.locator(`_react=BookItem[name = "the great gatsby" s]`)).toHaveCountError(0);
- await expect(page.locator(`_react=BookItem[name = "the great gatsby" S]`)).toHaveCountError(0);
- // case insensitive with flag
- await expect(page.locator(`_react=BookItem[name = "the great gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name = "the great gatsby" I]`)).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name = " The Great Gatsby "]`)).toHaveCountError(0);
- });
-
- it('should partially match by props', async ({ page }) => {
- // Check partial matching
- await expect(page.locator(`_react=BookItem[name *= "Gatsby"]`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name *= "Gatsby"]`)).toHaveCountError(1);
- await expect(page.locator(`_react=[name *= "Gatsby"]`)).toHaveCountError(1);
-
- await expect(page.locator(`_react=BookItem[name = "Gatsby"]`)).toHaveCountError(0);
- });
-
- it('should support all string operators', async ({ page }) => {
- await expect(page.locator(`_react=ColorButton[color = "red"]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color |= "red"]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color $= "ed"]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color ^= "gr"]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color ~= "e"]`)).toHaveCountError(0);
- await expect(page.locator(`_react=BookItem[name ~= "gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_react=BookItem[name *= " gatsby" i]`)).toHaveCountError(1);
- });
-
- it('should support regex', async ({ page }) => {
- await expect(page.locator(`_react=ColorButton[color = /red/]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color = /^red$/]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color = /RED/i]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color = /[pqr]ed/]`)).toHaveCountError(3);
- await expect(page.locator(`_react=ColorButton[color = /[pq]ed/]`)).toHaveCountError(0);
- await expect(page.locator(`_react=BookItem[name = /gat.by/i]`)).toHaveCountError(1);
- });
-
- it('should support truthy querying', async ({ page }) => {
- await expect(page.locator(`_react=ColorButton[enabled]`)).toHaveCountError(5);
- });
-
- it('should support nested react trees', async ({ page }) => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
- await page.evaluate(() => {
- // @ts-ignore
- mountNestedApp();
- });
- await expect(async () => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(6);
- }).toPass();
- });
-
- it('should work with react memo', async ({ page }) => {
- it.skip(name === 'react15' || name === 'react16', 'Class components dont support memo');
- await expect(page.locator(`_react=ButtonGrid`)).toHaveCountError(9);
- });
-
- it('should work with multiroot react', async ({ page }) => {
- await it.step('mount second root', async () => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
- await page.evaluate(() => {
- const anotherRoot = document.createElement('div');
- anotherRoot.id = 'root2';
- document.body.append(anotherRoot);
- // @ts-ignore
- window.mountApp(anotherRoot);
- });
- await expect(async () => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(6);
- }).toPass();
- });
-
- 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 >> _react=BookItem')).toHaveCountError(3);
- await expect(page.locator('css=#root2 >> _react=BookItem')).toHaveCountError(4);
- });
- });
-
- it('should work with multiroot react inside shadow DOM', async ({ page }) => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
- await page.evaluate(() => {
- const anotherRoot = document.createElement('div');
- document.body.append(anotherRoot);
- const shadowRoot = anotherRoot.attachShadow({ mode: 'open' });
- // @ts-ignore
- window.mountApp(shadowRoot);
- });
- await expect(async () => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(6);
- }).toPass();
- });
-
- it('should work with multiroot react after unmount', async ({ page }) => {
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
-
- await page.evaluate(() => {
- const anotherRoot = document.createElement('div');
- document.body.append(anotherRoot);
- // @ts-ignore
- const newRoot = window.mountApp(anotherRoot);
- newRoot.unmount();
- });
- await expect(page.locator(`_react=BookItem`)).toHaveCountError(3);
- });
- });
-}
diff --git a/tests/page/selectors-vue.spec.ts b/tests/page/selectors-vue.spec.ts
deleted file mode 100644
index feee266a68..0000000000
--- a/tests/page/selectors-vue.spec.ts
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * 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 as baseExpect } from './pageTest';
-import type { Locator } from 'playwright-core';
-
-const expect = baseExpect.extend({
- async toHaveCountError(locator: Locator, expected: number) {
- try {
- await expect(locator).toHaveCount(expected);
- if (!expected)
- return { pass: true, message: () => 'Locator has expected count of 0' };
- return {
- pass: false,
- message: () => `Querying locator ${locator.toString()} should throw, but it did not.`,
- };
- } catch (e) {
- const message = (e as Error).message;
- try {
- expect(message).toContain(`"_vue" selector is not supported`);
- expect(message).toContain(`resolved to ${expected} element`);
- } catch (error) {
- return { pass: false, message: () => (error as Error).message };
- }
- return { pass: true, message: () => 'Error message is as expected' };
- }
- }
-});
-
-const vues = {
- 'vue2': '/reading-list/vue2.html',
- 'vue3': '/reading-list/vue3.html',
-};
-
-for (const [name, url] of Object.entries(vues)) {
- it.describe(name, () => {
- it.beforeEach(async ({ page, server }) => {
- await page.goto(server.PREFIX + url);
- });
-
- it('should work with single-root elements @smoke', async ({ page }) => {
- await expect(page.locator(`_vue=book-list`)).toHaveCountError(1);
- // count() was not working, see: https://github.com/microsoft/playwright/issues/12887
- await expect(page.locator(`_vue=book-list`)).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(3);
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(3);
- await expect(page.locator(`_vue=book-list >> _vue=book-item`)).toHaveCountError(3);
- await expect(page.locator(`_vue=book-item >> _vue=book-list`)).toHaveCountError(0);
- });
-
- it('should work with multi-root elements (fragments)', async ({ page }) => {
- it.skip(name === 'vue2', 'vue2 does not support fragments');
- await expect(page.locator(`_vue=Root`)).toHaveCountError(15);
- await expect(page.locator(`_vue=app-header`)).toHaveCountError(2);
- await expect(page.locator(`_vue=new-book`)).toHaveCountError(2);
- });
-
- it('should not crash when there is no match', async ({ page }) => {
- await expect(page.locator(`_vue=apps`)).toHaveCountError(0);
- await expect(page.locator(`_vue=book-li`)).toHaveCountError(0);
- });
-
- it('should compose', async ({ page }) => {
- await expect(page.locator(`_vue=book-item >> text=Gatsby`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- });
-
- it('should query by props combinations', async ({ page }) => {
- await expect(page.locator(`_vue=book-item[name="The Great Gatsby"]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name="the great gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=color-button[nested.index = 0]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=color-button[nested.nonexisting.index = 0]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=color-button[nested.index.nonexisting = 0]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=color-button[nested.index.nonexisting = 1]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=color-button[nested.value = 4.1]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=color-button[enabled = false]`)).toHaveCountError(4);
- await expect(page.locator(`_vue=color-button[enabled = true] `)).toHaveCountError(5);
- await expect(page.locator(`_vue=color-button[enabled = true][color = "red"]`)).toHaveCountError(2);
- await expect(page.locator(`_vue=color-button[enabled = true][color = "red"i][nested.index = 6]`)).toHaveCountError(1);
- });
-
- it('should exact match by props', async ({ page }) => {
- await expect(page.locator(`_vue=book-item[name = "The Great Gatsby"]`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name = "The Great Gatsby"]`)).toHaveCountError(1);
- // case sensitive by default
- await expect(page.locator(`_vue=book-item[name = "the great gatsby"]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=book-item[name = "the great gatsby" s]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=book-item[name = "the great gatsby" S]`)).toHaveCountError(0);
- // case insensitive with flag
- await expect(page.locator(`_vue=book-item[name = "the great gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name = "the great gatsby" I]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name = " The Great Gatsby "]`)).toHaveCountError(0);
- });
-
- it('should partially match by props', async ({ page }) => {
- // Check partial matching
- await expect(page.locator(`_vue=book-item[name *= "Gatsby"]`).locator(':scope:has-text("The Great Gatsby")')).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name *= "Gatsby"]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=[name *= "Gatsby"]`)).toHaveCountError(1);
-
- await expect(page.locator(`_vue=book-item[name = "Gatsby"]`)).toHaveCountError(0);
- });
-
- it('should support all string operators', async ({ page }) => {
- await expect(page.locator(`_vue=color-button[color = "red"]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color |= "red"]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color $= "ed"]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color ^= "gr"]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color ~= "e"]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=book-item[name ~= "gatsby" i]`)).toHaveCountError(1);
- await expect(page.locator(`_vue=book-item[name *= " gatsby" i]`)).toHaveCountError(1);
- });
-
- it('should support regex', async ({ page }) => {
- await expect(page.locator(`_vue=color-button[color = /red/]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color = /^red$/]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color = /RED/i]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color = /[pqr]ed/]`)).toHaveCountError(3);
- await expect(page.locator(`_vue=color-button[color = /[pq]ed/]`)).toHaveCountError(0);
- await expect(page.locator(`_vue=book-item[name = /gat.by/i]`)).toHaveCountError(1);
- });
-
- it('should support truthy querying', async ({ page }) => {
- await expect(page.locator(`_vue=color-button[enabled]`)).toHaveCountError(5);
- });
-
- it('should support nested vue trees', async ({ page }) => {
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(3);
- await page.evaluate(() => {
- // @ts-ignore
- mountNestedApp();
- });
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(6);
- });
-
- it('should work with multiroot react', async ({ page }) => {
- await it.step('mount second root', async () => {
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(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`)).toHaveCountError(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')).toHaveCountError(3);
- await expect(page.locator('css=#root2 >> _vue=book-item')).toHaveCountError(4);
- });
- });
-
- it('should work with multiroot vue inside shadow DOM', async ({ page }) => {
- await expect(page.locator(`_vue=book-item`)).toHaveCountError(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`)).toHaveCountError(6);
- });
- });
-}