@@ -86,6 +86,44 @@ it('adds queries as element commands scoped to element', async () => {
86
86
})
87
87
```
88
88
89
+ When using v7.19 or higher of WebdriverIO you can also use chainable queries.
90
+ Chainable queries are added to the browser and element as commands with the
91
+ format ` {query}$ ` .
92
+
93
+ ``` javascript
94
+ it (' can chain browser getBy queries' , async () => {
95
+ setupBrowser (browser)
96
+
97
+ await browser .getByTestId$ (' nested' ).getByText$ (' Button Text' ).click ()
98
+
99
+ const buttonText = await browser
100
+ .getByTestId$ (' nested' )
101
+ .getByText$ (' Button Text' )
102
+ .getText ()
103
+
104
+ expect (buttonText).toEqual (' Button Clicked' )
105
+ })
106
+
107
+ it (' can chain element getBy queries' , async () => {
108
+ const {getByTestId } = setupBrowser (browser)
109
+
110
+ const nested = await getByTestId (' nested' )
111
+ await nested .getByText$ (' Button Text' ).click ()
112
+
113
+ const buttonText = await browser .getByText$ (' Button Clicked' ).getText ()
114
+
115
+ expect (buttonText).toEqual (' Button Clicked' )
116
+ })
117
+
118
+ it (' can chain getAllBy queries' , async () => {
119
+ setupBrowser (browser)
120
+
121
+ await browser .getByTestId$ (' nested' ).getAllByText$ (' Button Text' )[0 ].click ()
122
+
123
+ expect (await browser .getAllByText (' Button Clicked' )).toHaveLength (1 )
124
+ })
125
+ ```
126
+
89
127
### ` within `
90
128
91
129
Accepts a WebdriverIO element and returns queries scoped to that element
@@ -156,6 +194,29 @@ declare global {
156
194
}
157
195
```
158
196
197
+ To add chainable query types you need to extend the above interfaces as well as
198
+ ` ChainablePromiseElement ` with ` WebdriverIOQueriesChainable ` :
199
+
200
+ ``` typescript
201
+ import {WebdriverIOQueriesChainable , WebdriverIOQueries } from ' ../../src'
202
+
203
+ declare global {
204
+ namespace WebdriverIO {
205
+ interface Browser
206
+ extends WebdriverIOQueries ,
207
+ WebdriverIOQueriesChainable <Browser > {}
208
+ interface Element
209
+ extends WebdriverIOQueries ,
210
+ WebdriverIOQueriesChainable <Element > {}
211
+ }
212
+ }
213
+
214
+ declare module ' webdriverio' {
215
+ interface ChainablePromiseElement <T extends WebdriverIO .Element | undefined >
216
+ extends WebdriverIOQueriesChainable <T > {}
217
+ }
218
+ ```
219
+
159
220
If you are finding an error similar to this:
160
221
161
222
``` typescript
0 commit comments