如何在 VS Code 上获得 WebdriverIO 自动完成

如何在 VS Code 上获得 WebdriverIO 自动完成

问题描述:

有没有办法在 VS Code for webdriverio 上自动完成?

Is there a way I can get autocomplete on VS Code for webdriverio?

其他代码编辑器如 Intellij 提供类似设置 -> 首选项 -> 语言 &框架 -> JavaScript -> 库从那里我们可以添加一个带有 webdriverio 命令的目录

Other code editors like Intellij provide something like Settings -> Preferences -> Languages & Frameworks -> JavaScript -> Libraries From there we can add a directory with webdriverio commands

如何使用 VS Code 做类似的事情?

How can I do similar thing with VS Code?

我的理解是,vscode 是使用 typescript 构建的,默认情况下它不支持构建的包上的 autoComplete(Intellisense)使用 javascript.所以所有的 js 包创建者都会提供一个 @types 文件.这些 @types 文件帮助 vscode 找到所有的函数定义、对象属性.等等,等等,你的 JS 包并显示为建议.如果这里是 webdriverio 包.

my understanding is, vscode is built with typescript and by default it does not support autoComplete(Intellisense) on a package that is built with javascript. So all the js package creators would provide an @types file. These @types file help vscode to find all the function definitions, object properties. etc., etc., of your JS package and show as suggestions. Which in case here is webdriverio package.

因此,添加与您的 JS 包相关的 @types 依赖项将主要解决问题.即,

So adding a @types dependency that is related to your JS package will mostly fix the issue. i.e.,

npm install @types/webdriverio --save-dev

添加包后,我开始获取浏览器对象建议.

After adding the package, i started getting the browser object suggestions.

以上所有内容都适用于 v4 版本的 WDIO.

All the above works fine for v4 version of WDIO.

如果您使用的是 v5 版本:那么根据他们的官方文档,我们需要创建根目录下的 jsconfig.json 文件.

If you are using v5 version: Then as per their official documentation we need to create a jsconfig.json file on the root directory.