webdriverio: [šŸ› Bug]: Eslint `await-thenable` rule doesn't recognise async commands

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

7.22.0 and 8.0.0-alpha.412

Node.js Version

18

Mode

Standalone Mode

Which capabilities are you using?

const capabilities = {
  platformName: 'iOS',
  'appium:app':
    IOS_ZIP_PATH || 'https://github.com/appium/appium/raw/1.x/sample-code/apps/TestApp.app.zip',
  'appium:automationName': 'XCUITest',
  'appium:deviceName': IOS_DEVICE_NAME || 'iPhone 12',
  'appium:platformVersion': IOS_PLATFORM_VERSION || '15.5',
}

What happened?

import { remote, RemoteOptions } from 'webdriverio'

const { IOS_ZIP_PATH, IOS_DEVICE_NAME, IOS_PLATFORM_VERSION } = process.env

const capabilities = {
  platformName: 'iOS',
  'appium:app':
    IOS_ZIP_PATH || 'https://github.com/appium/appium/raw/1.x/sample-code/apps/TestApp.app.zip',
  'appium:automationName': 'XCUITest',
  'appium:deviceName': IOS_DEVICE_NAME || 'iPhone 12',
  'appium:platformVersion': IOS_PLATFORM_VERSION || '15.5',
}

const wdOpts: RemoteOptions = {
  port: 4723,
  logLevel: 'info',
  capabilities,
}

describe('ios', () => {
  let driver: WebdriverIO.Browser | undefined

  beforeAll(async () => {
    driver = await remote(wdOpts)
    expect(driver).toBeDefined()
  })

  afterEach(async () => {
    await driver.deleteSession()
  })

  it('should type "Hello World!" and retrieve value in input', async () => {
    const elementId = await driver.findElement('accessibility id', 'IntegerA')
    driver.elementSendKeys(elementId.ELEMENT, 'Hello World!')

    const elementValue = await driver.findElement('accessibility id', 'IntegerA')
    const attr = await driver.getElementAttribute(elementValue.ELEMENT, 'value')
    expect(attr).toEqual('Hello World!')
  })

  it('should click on "show alert" and read alert text', async () => {
    const element = await driver.findElement('accessibility id', 'show alert')
    await driver.elementClick(element.ELEMENT)
    const alertText = await driver.getAlertText()
    expect(alertText).toEqual(`Cool title this alert is so cool.`)
  })
})

Ide shows Redundant 'await' for a non-promise type for driver.getElementAttribute and driver.getAlertText(), looking at the typing he is right:

    /**
     * Webdriver Protocol Command
     *
     * The Get Element Attribute command will return the attribute of a web element.
     * @ref https://w3c.github.io/webdriver/#dfn-get-element-attribute
     *
     */
    getElementAttribute(elementId: string, name: string): string;
    getAlertText(): string;
    /**
     * Webdriver Protocol Command
     *
     * The Send Alert Text command sets the text field of a window.prompt user prompt to the given value.
     * @ref https://w3c.github.io/webdriver/#dfn-send-alert-text
     *
     */

I have similar problem with element return by getElementAttribute:

TS2339: Property 'ELEMENT' does not exist on type 'ElementReference'.

I presume there’s something wrong, maybe wrong package ?

What is your expected behavior?

Typing to work well

How to reproduce the bug.

Copy the test, test it.

Try to remove, the await, it will break.

Relevant log output

![image](https://user-images.githubusercontent.com/77674046/198309961-61b119af-db60-4650-8f87-c578d84fd9ab.png)

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Using both in one repo shouldn’t be an issue, you can use the following structure:

- src

- test
 - tsconfig.json

tsconfig.json // exclude test

If you want to place the test files next to the frontend code then there’s a bit of a challenge depending on your setup. The next release (v8) will allow you to import the global types instead which should solve such challenges.

I just had a check and :

This repository does only provide one typescript setup : https://github.com/webdriverio/appium-boilerplate/blob/main/tsconfig.json

This won’t work for us as we store the react-native app and the e2e on the same repo, but that’s a whole topic on it’s own, let’s just ignore that.

It also use a deprecated version of appium , upgrading should be quite simple.

All those specs given here are gold, I will clone it and see if I can reproduce the typing issue.

And for sure I will learn them all.

Sorry, I had to rename the branch : https://github.com/pass-culture/pass-culture-app-native/pull/3838

I will have a look to the boilerplate. Thanks !

I posted are from 7.22.0 and 8.0.0-alpha.412

I used latest which is 7.22.0. The other version is not released yet.

Those declaration are incorrect so if you are using the same versions, how can’t you have the same problem when calling those methods ?

Can be many things, wrong TS setup may be one.

as i still think this issue deserve to be treated because I demonstrated with all details the typing issue

I am helping you here and just because I closed it doesn’t mean I leave you hanging. I think the best we can do is you providing a minimal reproducible example that I can check out and look into. What do you think?

TS2339: Property ā€˜ELEMENT’ does not exist on type ā€˜ElementReference’.

This is a legit error, if you use findElement the WebDriver response doesn’t contain an ELEMENT.

Fixing this results in:

  it('should type "Hello World!" and retrieve value in input', async () => {
    const elementId = await driver.findElement('accessibility id', 'IntegerA')
    driver.elementSendKeys(elementId['element-6066-11e4-a52e-4f735466cecf'], 'Hello World!')

    const elementValue = await driver.findElement('accessibility id', 'IntegerA')
    const attr = await driver.getElementAttribute(elementId['element-6066-11e4-a52e-4f735466cecf'], 'value')
    expect(attr).toEqual('Hello World!')
  })

  it('should click on "show alert" and read alert text', async () => {
    const element = await driver.findElement('accessibility id', 'show alert')
    await driver.elementClick(element['element-6066-11e4-a52e-4f735466cecf'])
    const alertText = await driver.getAlertText()
    expect(alertText).toEqual(`Cool title this alert is so cool.`)
  })

which does not have any TS errors.