33import path from 'path'
44import fs from 'fs'
55import { queries as baseQueries } from '@testing-library/dom'
6- import { Element , BrowserObject , MultiRemoteBrowserObject } from 'webdriverio'
76
8- import { Config , QueryName , WebdriverIOQueries } from './types'
7+ import {
8+ BrowserBase ,
9+ Config ,
10+ ElementBase ,
11+ QueryName ,
12+ WebdriverIOQueries ,
13+ } from './types'
914
1015declare global {
1116 interface Window {
@@ -26,7 +31,7 @@ const DOM_TESTING_LIBRARY_UMD = fs
2631
2732let _config : Partial < Config >
2833
29- async function injectDOMTestingLibrary ( container : Element ) {
34+ async function injectDOMTestingLibrary ( container : ElementBase ) {
3035 const shouldInject = await container . execute ( function ( ) {
3136 return ! window . TestingLibraryDom
3237 } )
@@ -108,18 +113,18 @@ Element. There are valid WebElement JSONs that exclude the key but can be turned
108113into Elements, such as { ELEMENT: elementId }; this can happen in setups that
109114aren't generated by @wdio/cli.
110115*/
111- function createElement ( container : Element , elementValue : any ) {
116+ function createElement ( container : ElementBase , elementValue : any ) {
112117 return container . $ ( {
113118 'element-6066-11e4-a52e-4f735466cecf' : '' ,
114119 ...elementValue ,
115120 } )
116121}
117122
118- function createQuery ( element : Element , queryName : string ) {
123+ function createQuery ( element : ElementBase , queryName : string ) {
119124 return async ( ...args : any [ ] ) => {
120125 await injectDOMTestingLibrary ( element )
121126
122- const result = await element . executeAsync < any [ ] , any [ ] > ( executeQuery , [
127+ const result = await element . executeAsync ( executeQuery , [
123128 queryName ,
124129 element ,
125130 ...args . map ( serializeArg ) ,
@@ -141,7 +146,7 @@ function createQuery(element: Element, queryName: string) {
141146 }
142147}
143148
144- function within ( element : Element ) {
149+ function within ( element : ElementBase ) {
145150 return Object . keys ( baseQueries ) . reduce (
146151 ( queries , queryName ) => ( {
147152 ...queries ,
@@ -151,7 +156,7 @@ function within(element: Element) {
151156 ) as WebdriverIOQueries
152157}
153158
154- function setupBrowser ( browser : BrowserObject | MultiRemoteBrowserObject ) {
159+ function setupBrowser ( browser : BrowserBase ) {
155160 const queries : { [ key : string ] : any } = { }
156161
157162 Object . keys ( baseQueries ) . forEach ( ( key ) => {
@@ -171,9 +176,8 @@ function setupBrowser(browser: BrowserObject | MultiRemoteBrowserObject) {
171176 // add query to Elements
172177 browser . addCommand (
173178 queryName ,
174- function ( ...args : any [ ] ) {
175- const element = this as Element
176- return within ( element ) [ queryName ] ( ...args )
179+ function ( this , ...args ) {
180+ return within ( this ) [ queryName ] ( ...args )
177181 } ,
178182 true ,
179183 )
0 commit comments