typescripttestingwebdriver-iowdio

What type should I use for browser elements in typescript in wdio tests?


I'm trying to figure out how to type browser elements. Code example (??? marks the place where you need to add the type):

login_input = await $('div.login_input')
await set_login('login', login_input)

set_login = async (
  login: string, login_input: ???
): Promise<void> => {
  await login_input.setValue(login);
}

This source https://github.com/webdriverio/webdriverio/issues/7767 says that for browser elements you need to use the type ChainablePromiseElement<Promise< Element>>, but if i do it, i have this error: Type 'ChainablePromiseElement' is not generic

I would be grateful for your help!


Solution

  • I found the answer in the wdio support chat. Need to use type WebdriverIO.Element

    set_login = async (
      login: string, login_input: WebdriverIO.Element
    ): Promise<void> => {
      await login_input.setValue(login);
    }