【问题标题】:Webdriver io autocomplete in VS CodeVS Code 中的 Webdriver io 自动完成
【发布时间】:2017-12-26 22:33:48
【问题描述】:

我使用 Webdriver IO 作为 e2e 测试框架。但是这个自动完成问题真的让我慢了下来。 VS Code 不会自动补全全局变量 browser 及其方法。

.eslintrc

{
    "extends": ["eslint:recommended", "standard"],
    "parser": "babel-eslint",
    "plugins": [
        "mocha",
        "webdriverio"
    ],
    "env": {
        "webdriverio/wdio": true,
        "mocha": true
    },
    "parserOptions": {
      "ecmaVersion": 8,
      "sourceType": "module"
    },
    "rules": {
        "indent": ["error", 4]
    }
}

.babelrc

{
  "presets": ["es2015"],
  "plugins": [
    ["transform-runtime", {
      "polyfill": false
    }]
  ]
}

【问题讨论】:

    标签: selenium visual-studio-code webdriver-io


    【解决方案1】:

    我认为你可以使用 TypeScript 类型。

    在 package.json 中添加 2 个依赖项:

    "@types/node": "^8.5.2",
    "@types/webdriverio": "^4.8.7",
    

    安装它们,重新加载项目。如果自动完成功能还不起作用,请创建 tsconfig.json 在项目的根目录中:

    {
      "compilerOptions": {
        "allowJs": true,
        "outDir": "./.built/"
      }
    }
    

    您不需要使用 typescript 编译器,它只会提供自动完成功能。像往常一样继续编写你的 js 代码。

    但是如果你想使用打字稿,这里有一个小的初学者指南: http://webdriver.io/guide/getstarted/configuration.html#Setup-TypeScript

    【讨论】:

    • 哦,哇,我现在感觉好傻,我有 typescript 版本,但在转换为 ES6 后我删除了依赖项......非常感谢!
    • 它就像一个魅力。非常感谢你。在撰写本文时,上述软件包的最新版本存在问题。安装答案中提到的版本。
    猜你喜欢
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 2016-09-02
    • 2021-10-30
    • 1970-01-01
    • 2017-11-21
    • 2022-01-13
    相关资源
    最近更新 更多