VS Code automatically adds parenthesis around await statement
Asked Answered
D

4

10

I'm writing some tests in selenium webdriver js. I start by typing:

it('blah blah blah', async () => {
    await driver
})

Then I type . after driver. Suggestions come up. Then I select findElement from the list.

Then VS Code "intelligently" changes my code to:

await (await driver).findElement

This is annoying, as I have to manually remove the additional parenthesis and await. Any fix for this?

Delmydeloach answered 18/1, 2020 at 18:20 Comment(3)
Did you ever find out why this was happening?Succursal
I'm also having this problem, and this is the only place where I found someone asking the same question. Have you figured it out?Decussate
I'm getting this as well - really wish we had a solution - it just started happening today after working with puppeteer and playwrightRunnymede
I
0

This issue had been raised here: Bug 1 and here: Bug 2.

A fix for the bug seems to be merged for WDIO v9: https://github.com/webdriverio/webdriverio/pull/13051

Inwrap answered 17/7 at 11:28 Comment(0)
P
-1

I have the same issue and will follow-up with code. To be clear, if I undo the annoying: const userMenu = await (await driver).findElement, and return it to what I typed, and not what VSCode decided I meant, const userMenu = await driver.findElement, it works. Everything works. I'm logging in, opening stuff, interacting with forms. All is well, other than this pesky auto-text (await driver) being inserted after I write findElement.

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());

const driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.chrome().set('chromeOptions', {'args': ['--auto-open-devtools-for-tabs', '--start-maximized']}))
    // .setChromeOptions()
    .build();
Phratry answered 16/4, 2020 at 17:54 Comment(0)
L
-1

This is coming from @wdio/globals/types. You can resolve it by removing it from compilerOptions in your jsonconfig.json file.

Lobectomy answered 18/1, 2023 at 15:20 Comment(2)
Doesnt work for me :(Outmarch
This just removes support for all wdio types; and thus for Intellisense for any webdriver code. Not a solution.Noxious
P
-2

My guess is that you forgot to resolve new Builder().build(), so your driver was actually a Promise. Could you give the full code?

Photocompose answered 31/1, 2020 at 6:34 Comment(1)
Why, then, would all my code sucessfully automate processes after fixing the await (await driver).findElement? I'm having the same issue.Phratry

© 2022 - 2024 — McMap. All rights reserved.