@@ -16,6 +16,9 @@ const {
1616 getElementText,
1717 getElementAttribute,
1818 getActiveElement,
19+ elementClick,
20+ getElementRect,
21+ getScreenshot,
1922} = await import ( '../command.js' ) ;
2023
2124// What the remote client resolves with when it swallows a "no such element" 404.
@@ -123,6 +126,54 @@ describe('element commands: re-throw swallowed remote "no such element"', () =>
123126 ) . resolves . toBe ( el ) ;
124127 } ) ;
125128
129+ test ( 'elementClick re-throws swallowed error, resolves otherwise' , async ( ) => {
130+ await expect (
131+ elementClick (
132+ { elementClick : jest . fn ( async ( ) => NO_SUCH_ELEMENT_VALUE ) } as never ,
133+ 'bad'
134+ )
135+ ) . rejects . toThrow ( / c o u l d n o t b e l o c a t e d / i) ;
136+ await expect (
137+ elementClick (
138+ { elementClick : jest . fn ( async ( ) => undefined ) } as never ,
139+ 'el'
140+ )
141+ ) . resolves . toBeUndefined ( ) ;
142+ } ) ;
143+
144+ test ( 'getElementRect re-throws swallowed error, returns rect otherwise' , async ( ) => {
145+ await expect (
146+ getElementRect (
147+ { getElementRect : jest . fn ( async ( ) => NO_SUCH_ELEMENT_VALUE ) } as never ,
148+ 'bad'
149+ )
150+ ) . rejects . toThrow ( / c o u l d n o t b e l o c a t e d / i) ;
151+ const rect = { x : 0 , y : 0 , width : 100 , height : 40 } ;
152+ await expect (
153+ getElementRect (
154+ { getElementRect : jest . fn ( async ( ) => rect ) } as never ,
155+ 'el'
156+ )
157+ ) . resolves . toBe ( rect ) ;
158+ } ) ;
159+
160+ test ( 'getScreenshot(elementId) re-throws swallowed error, returns base64 otherwise' , async ( ) => {
161+ await expect (
162+ getScreenshot (
163+ {
164+ takeElementScreenshot : jest . fn ( async ( ) => NO_SUCH_ELEMENT_VALUE ) ,
165+ } as never ,
166+ 'bad'
167+ )
168+ ) . rejects . toThrow ( / c o u l d n o t b e l o c a t e d / i) ;
169+ await expect (
170+ getScreenshot (
171+ { takeElementScreenshot : jest . fn ( async ( ) => 'base64png' ) } as never ,
172+ 'el'
173+ )
174+ ) . resolves . toBe ( 'base64png' ) ;
175+ } ) ;
176+
126177 test ( 'preserves the W3C error code as the error name (for classifyError)' , async ( ) => {
127178 await expect (
128179 getElementText (
0 commit comments