playwright-ui5 1.5.0 → 1.6.0
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 +100 -5
- package/dist/browser/css.js +1166 -0
- package/dist/browser/xpath.js +29155 -0
- package/dist/node/main.d.ts +14 -2
- package/dist/node/main.d.ts.map +1 -1
- package/dist/node/main.js +10 -4
- package/dist/node/main.js.map +1 -1
- package/package.json +19 -12
- package/src/node/main.ts +10 -4
- package/dist/browser/main.js +0 -1474
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# playwright ui5
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
playwright [custom selector engines](https://playwright.dev/docs/extensibility#custom-selector-engines) for [sapui5](https://ui5.sap.com/)
|
|
4
4
|
|
|
5
5
|
## installation
|
|
6
6
|
|
|
@@ -10,12 +10,16 @@ npm install playwright-ui5
|
|
|
10
10
|
|
|
11
11
|
## usage
|
|
12
12
|
|
|
13
|
+
playwright-ui5 contains a selector engine for both css and xpath syntax. you can use whichever one you want, but the xpath one is more flexible since not all css selector syntax has been implemented yet.
|
|
14
|
+
|
|
15
|
+
### css selector engine
|
|
16
|
+
|
|
13
17
|
```ts
|
|
14
18
|
import { selectors, test } from '@playwright/test'
|
|
15
|
-
import
|
|
19
|
+
import { css } from 'playwright-ui5'
|
|
16
20
|
|
|
17
21
|
test.beforeAll(async () => {
|
|
18
|
-
await selectors.register('ui5',
|
|
22
|
+
await selectors.register('ui5', css)
|
|
19
23
|
})
|
|
20
24
|
|
|
21
25
|
test('ui5 example', ({ page }) => {
|
|
@@ -24,9 +28,9 @@ test('ui5 example', ({ page }) => {
|
|
|
24
28
|
})
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
#### syntax
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
the main difference between regular CSS selectors and playwright-ui5's syntax is is that `.` is not used for class names, rather they are treated as part of the type name (ie. `sap.m.Button`).
|
|
30
34
|
|
|
31
35
|
| feature | examples | suported | notes |
|
|
32
36
|
| ------------------- | ---------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -38,3 +42,94 @@ this selector engine uses css selector-like syntax. the main difference is that
|
|
|
38
42
|
| pseudo-classes | `sap.m.Table:has(sap.m.Button)` | ✔ | only `:has` is supported for now |
|
|
39
43
|
| pseudo-elements | `sap.m.DateTimeField::subclass` | ✔ | `::subclass` will match the specified control type and any subtypes (eg. both `sap.m.DateTimeField` and subtypes like `sap.m.DatePicker`) |
|
|
40
44
|
| selector lists | `sap.m.Button,sap.m.Table` | ✔ |
|
|
45
|
+
|
|
46
|
+
### xpath selector engine
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { selectors, test } from '@playwright/test'
|
|
50
|
+
import { xpath } from 'playwright-ui5'
|
|
51
|
+
|
|
52
|
+
test.beforeAll(async () => {
|
|
53
|
+
await selectors.register('ui5', xpath)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('ui5 example', ({ page }) => {
|
|
57
|
+
await page.goto('https://ui5.sap.com/')
|
|
58
|
+
await page.click("ui5=//sap.m.Button[ui5:property(., 'text')='Get Started with UI5']")
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### syntax
|
|
63
|
+
|
|
64
|
+
unlike the CSS selector syntax, all xpath syntax is supported (even newer xpath features up to version 3.1 thanks to [fontoxpath](https://github.com/FontoXML/fontoxpath)).
|
|
65
|
+
|
|
66
|
+
note that properties cannot be accessed via the `@attribute` syntax. this is because the selector engine needs to build an XML tree of all the ui5 elements on the page, and for performance reasons the properties are not evaluated during this step, so the only attribute that can be accessed that way is the element's ID.
|
|
67
|
+
|
|
68
|
+
for example, for a button with the id `"foo"` and the text `"bar"`, the xml view may look like this:
|
|
69
|
+
|
|
70
|
+
```xml
|
|
71
|
+
<sap.m.Page id="__page0">
|
|
72
|
+
<sap.m.Button id="foo"></sap.m.Button>
|
|
73
|
+
</sap.m.Page>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
in this case, `//sap.m.Button[@id='foo']` will work, but `//sap.m.Button[@text='bar']` will not. to access the property, you can use the [`ui5:property`](#ui5property) xpath function instead, like so:
|
|
77
|
+
|
|
78
|
+
```xpath
|
|
79
|
+
//sap.m.Button[ui5:property(., 'text')='bar']
|
|
80
|
+
```
|
|
81
|
+
|
|
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
|
+
|
|
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
|
+
|
|
99
|
+
#### API
|
|
100
|
+
|
|
101
|
+
the following xpath functions are available in the `ui5:` namespace:
|
|
102
|
+
|
|
103
|
+
##### `ui5:property`
|
|
104
|
+
|
|
105
|
+
- **arguments:** `element()`, `xs:string`
|
|
106
|
+
- **return type:** `item()*`
|
|
107
|
+
|
|
108
|
+
gets the value for the property with the specified name from the specified element
|
|
109
|
+
|
|
110
|
+
```xpath
|
|
111
|
+
//sap.m.Button[ui5:property(., "text")="Click here"]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
##### `ui5:debug-xml`
|
|
115
|
+
|
|
116
|
+
- **arguments:** `element()`
|
|
117
|
+
- **return type:** N/A (always throws an exception)
|
|
118
|
+
|
|
119
|
+
raises an exception containining the XML control tree with the specified element as the root. this function is only intended for debugging purposes.
|
|
120
|
+
|
|
121
|
+
```xpath
|
|
122
|
+
ui5:debug-xml(root)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
this will throw an exception containing the entire control tree for the page in XML format:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
playwright-ui5 debug-xml function was called. here is the XML element tree:
|
|
129
|
+
|
|
130
|
+
<root>
|
|
131
|
+
<sap-ui-area id="sap-ui-static">
|
|
132
|
+
<!-- ... -->
|
|
133
|
+
</sap-ui-area>
|
|
134
|
+
</root>
|
|
135
|
+
```
|