playwright-ui5 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/browser/xpath.js +27 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,21 @@ in this case, `//sap.m.Button[@id='foo']` will work, but `//sap.m.Button[@text='
|
|
|
81
81
|
|
|
82
82
|
the XML view matches the control tree from the [ui5 diagnostics window](https://sapui5.hana.ondemand.com/sdk/#/topic/04b75eae78ef4bae9b40cd7540ae8bdc) and the [ui5 inspector chrome extension](https://chromewebstore.google.com/detail/ui5-inspector/bebecogbafbighhaildooiibipcnbngo), so we recommend using one of these when working with the ui5 xpath selector engine.
|
|
83
83
|
|
|
84
|
+
#### the root node
|
|
85
|
+
|
|
86
|
+
since the ui5 control tree can have multiple root nodes, the xpath selector engine wraps `sap-ui-area` nodes inside a `root` node:
|
|
87
|
+
|
|
88
|
+
```xml
|
|
89
|
+
<root>
|
|
90
|
+
<sap-ui-area id="sap-ui-static">
|
|
91
|
+
<sap.m.Page id="__page0">
|
|
92
|
+
<sap.m.Button id="foo"></sap.m.Button>
|
|
93
|
+
</sap.m.Page>
|
|
94
|
+
</sap-ui-area>
|
|
95
|
+
<sap-ui-area id="canvas">
|
|
96
|
+
</root>
|
|
97
|
+
```
|
|
98
|
+
|
|
84
99
|
#### API
|
|
85
100
|
|
|
86
101
|
the following xpath functions are available in the `ui5:` namespace:
|
package/dist/browser/xpath.js
CHANGED
|
@@ -29053,8 +29053,11 @@ var createTreeModelNodes = (node) => {
|
|
|
29053
29053
|
inner(node, result);
|
|
29054
29054
|
return result;
|
|
29055
29055
|
};
|
|
29056
|
-
var
|
|
29056
|
+
var createXmlFromTreeNodes = (treeModelNodes) => {
|
|
29057
29057
|
let xml = (0, import_xmlbuilder2.create)({ version: "1.0" });
|
|
29058
|
+
if (treeModelNodes[0]?.name === "sap-ui-area") {
|
|
29059
|
+
xml = xml.ele("root");
|
|
29060
|
+
}
|
|
29058
29061
|
const inner = (nodes) => {
|
|
29059
29062
|
nodes.forEach((node) => {
|
|
29060
29063
|
xml = xml.ele(node.name, { id: node.id });
|
|
@@ -29062,10 +29065,10 @@ var createXmlFromTreeNode = (treeModelNode) => {
|
|
|
29062
29065
|
xml = xml.up();
|
|
29063
29066
|
});
|
|
29064
29067
|
};
|
|
29065
|
-
inner(
|
|
29068
|
+
inner(treeModelNodes);
|
|
29066
29069
|
return xml.end({ prettyPrint: true });
|
|
29067
29070
|
};
|
|
29068
|
-
var createXml = (nodeElement) => createTreeModelNodes(nodeElement)
|
|
29071
|
+
var createXml = (nodeElement) => createXmlFromTreeNodes(createTreeModelNodes(nodeElement));
|
|
29069
29072
|
var namespaceURI = "ui5";
|
|
29070
29073
|
registerCustomXPathFunction(
|
|
29071
29074
|
{ namespaceURI, localName: "property" },
|
|
@@ -29103,26 +29106,23 @@ ${element.outerHTML}`
|
|
|
29103
29106
|
var options = {
|
|
29104
29107
|
namespaceResolver: (prefix) => prefix === namespaceURI ? prefix : null
|
|
29105
29108
|
};
|
|
29106
|
-
var
|
|
29107
|
-
var
|
|
29108
|
-
|
|
29109
|
-
|
|
29110
|
-
|
|
29111
|
-
|
|
29112
|
-
|
|
29113
|
-
return
|
|
29109
|
+
var getRootElement = (node) => (node instanceof Element ? node.ownerDocument : node).querySelector("*");
|
|
29110
|
+
var createXmlDom = (node) => {
|
|
29111
|
+
const root = getRootElement(node);
|
|
29112
|
+
if (root === null) {
|
|
29113
|
+
return void 0;
|
|
29114
|
+
}
|
|
29115
|
+
const result = new DOMParser().parseFromString(createXml(root), "text/xml");
|
|
29116
|
+
return node instanceof Element ? result.getElementById(node.id) : result;
|
|
29114
29117
|
};
|
|
29118
|
+
var matchXmlElementToHtmlElement = (root, element) => getRootElement(root)?.querySelector(`[id='${element.id}']`) ?? void 0;
|
|
29115
29119
|
var xpath_default = {
|
|
29116
29120
|
queryAll: (root, selector) => {
|
|
29117
29121
|
try {
|
|
29118
29122
|
if (!isUi5()) {
|
|
29119
29123
|
return [];
|
|
29120
29124
|
}
|
|
29121
|
-
return
|
|
29122
|
-
(node) => createXmlDoms(node).flatMap(
|
|
29123
|
-
(xmlDom) => evaluateXPathToNodes(selector, xmlDom, null, null, options)
|
|
29124
|
-
).flatMap((element) => matchXmlElementToHtmlElement(root, element))
|
|
29125
|
-
);
|
|
29125
|
+
return evaluateXPathToNodes(selector, createXmlDom(root), null, null, options).map((element) => matchXmlElementToHtmlElement(root, element)).filter((element) => element !== void 0);
|
|
29126
29126
|
} catch (e4) {
|
|
29127
29127
|
throw new Ui5SelectorEngineError(selector, e4);
|
|
29128
29128
|
}
|
|
@@ -29132,21 +29132,18 @@ var xpath_default = {
|
|
|
29132
29132
|
if (!isUi5()) {
|
|
29133
29133
|
return void 0;
|
|
29134
29134
|
}
|
|
29135
|
-
|
|
29136
|
-
|
|
29137
|
-
|
|
29138
|
-
selector,
|
|
29139
|
-
xmlDom,
|
|
29140
|
-
null,
|
|
29141
|
-
null,
|
|
29142
|
-
options
|
|
29143
|
-
);
|
|
29144
|
-
if (result) {
|
|
29145
|
-
return matchXmlElementToHtmlElement(root, result)[0];
|
|
29146
|
-
}
|
|
29147
|
-
}
|
|
29135
|
+
const node = getRootElement(root);
|
|
29136
|
+
if (node === null) {
|
|
29137
|
+
return void 0;
|
|
29148
29138
|
}
|
|
29149
|
-
|
|
29139
|
+
const result = evaluateXPathToFirstNode(
|
|
29140
|
+
selector,
|
|
29141
|
+
createXmlDom(node),
|
|
29142
|
+
null,
|
|
29143
|
+
null,
|
|
29144
|
+
options
|
|
29145
|
+
);
|
|
29146
|
+
return result ? matchXmlElementToHtmlElement(root, result) : void 0;
|
|
29150
29147
|
} catch (e4) {
|
|
29151
29148
|
throw new Ui5SelectorEngineError(selector, e4);
|
|
29152
29149
|
}
|