Typescript无法识别WebDriverIO符号

Typescript无法识别WebDriverIO符号,typescript,webdriver-io,ui-testing,Typescript,Webdriver Io,Ui Testing,我正在尝试用Typescript进行UI自动化测试。当我运行测试时,它无法识别wdio.conf.js中声明的browser对象或$symbol。这是一个代码示例。我正在共享一个屏幕截图,以便您可以看到VSCode正在对其进行红线批注: 我在这里有我的wdio.conf.js文件: exports.config = { // // ==================== // Runner Configuration // ==================

我正在尝试用Typescript进行UI自动化测试。当我运行测试时,它无法识别wdio.conf.js中声明的
browser
对象或$symbol。这是一个代码示例。我正在共享一个屏幕截图,以便您可以看到VSCode正在对其进行红线批注:

我在这里有我的wdio.conf.js文件:

exports.config = {
    //
    // ====================
    // Runner Configuration
    // ====================
    //
    // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
    // on a remote machine).
    runner: 'local',
    //
    // ==================
    // Specify Test Files
    // ==================
    // Define which test specs should run. The pattern is relative to the directory
    // from which `wdio` was called.
    //
    // The specs are defined as an array of spec files (optionally using wildcards
    // that will be expanded). The test for each spec file will be run in a separate
    // worker process. In order to have a group of spec files run in the same worker
    // process simply enclose them in an array within the specs array.
    //
    // If you are calling `wdio` from an NPM script (see https://docs.npmjs.com/cli/run-script),
    // then the current working directory is where your `package.json` resides, so `wdio`
    // will be called from there.
    //
    specs: [
        './test/specs/*.ts'
    ],
    // Patterns to exclude.
    exclude: [
        // 'path/to/excluded/files'
    ],
    //
    // ============
    // Capabilities
    // ============
    // Define your capabilities here. WebdriverIO can run multiple capabilities at the same
    // time. Depending on the number of capabilities, WebdriverIO launches several test
    // sessions. Within your capabilities you can overwrite the spec and exclude options in
    // order to group specific specs to a specific capability.
    //
    // First, you can define how many instances should be started at the same time. Let's
    // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
    // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
    // files and you set maxInstances to 10, all spec files will get tested at the same time
    // and 30 processes will get spawned. The property handles how many capabilities
    // from the same test should run tests.
    //
    maxInstances: 10,
    //
    // If you have trouble getting all important capabilities together, check out the
    // Sauce Labs platform configurator - a great tool to configure your capabilities:
    // https://docs.saucelabs.com/reference/platforms-configurator
    //
    capabilities: [{
    
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        maxInstances: 5,
        //
        browserName: 'chrome',
        acceptInsecureCerts: true
        // If outputDir is provided WebdriverIO can capture driver session logs
        // it is possible to configure which logTypes to include/exclude.
        // excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
        // excludeDriverLogs: ['bugreport', 'server'],
    }],
    //
    // ===================
    // Test Configurations
    // ===================
    // Define all options that are relevant for the WebdriverIO instance here
    //
    // Level of logging verbosity: trace | debug | info | warn | error | silent
    logLevel: 'info',
    //
    // Set specific log levels per logger
    // loggers:
    // - webdriver, webdriverio
    // - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service
    // - @wdio/mocha-framework, @wdio/jasmine-framework
    // - @wdio/local-runner
    // - @wdio/sumologic-reporter
    // - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils
    // Level of logging verbosity: trace | debug | info | warn | error | silent
    // logLevels: {
    //     webdriver: 'info',
    //     '@wdio/applitools-service': 'info'
    // },
    //
    // If you only want to run your tests until a specific amount of tests have failed use
    // bail (default is 0 - don't bail, run all tests).
    bail: 0,
    //
    // Set a base URL in order to shorten url command calls. If your `url` parameter starts
    // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
    // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
    // gets prepended directly.
    baseUrl: 'http://localhost',
    //
    // Default timeout for all waitFor* commands.
    waitforTimeout: 10000,
    //
    // Default timeout in milliseconds for request
    // if browser driver or grid doesn't send response
    connectionRetryTimeout: 120000,
    //
    // Default request retries count
    connectionRetryCount: 3,
    //
    // Test runner services
    // Services take over a specific job you don't want to take care of. They enhance
    // your test setup with almost no effort. Unlike plugins, they don't add new
    // commands. Instead, they hook themselves up into the test process.
    services: ['chromedriver'],
    
    // Framework you want to run your specs with.
    // The following are supported: Mocha, Jasmine, and Cucumber
    // see also: https://webdriver.io/docs/frameworks
    //
    // Make sure you have the wdio adapter package for the specific framework installed
    // before running any tests.
    framework: 'mocha',
    //
    // The number of times to retry the entire specfile when it fails as a whole
    // specFileRetries: 1,
    //
    // Delay in seconds between the spec file retry attempts
    // specFileRetriesDelay: 0,
    //
    // Whether or not retried specfiles should be retried immediately or deferred to the end of the queue
    // specFileRetriesDeferred: false,
    //
    // Test reporter for stdout.
    // The only one supported by default is 'dot'
    // see also: https://webdriver.io/docs/dot-reporter
    reporters: ['spec'],


    
    //
    // Options to be passed to Mocha.
    // See the full list at http://mochajs.org/
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    },
    //
    // =====
    // Hooks
    // =====
    // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
    // it and to build services around it. You can either apply a single function or an array of
    // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
    // resolved to continue.
    /**
     * Gets executed once before all workers get launched.
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     */
    // onPrepare: function (config, capabilities) {
    // },
    /**
     * Gets executed before a worker process is spawned and can be used to initialise specific service
     * for that worker as well as modify runtime environments in an async fashion.
     * @param  {String} cid      capability id (e.g 0-0)
     * @param  {[type]} caps     object containing capabilities for session that will be spawn in the worker
     * @param  {[type]} specs    specs to be run in the worker process
     * @param  {[type]} args     object that will be merged with the main configuration once worker is initialised
     * @param  {[type]} execArgv list of string arguments passed to the worker process
     */
    // onWorkerStart: function (cid, caps, specs, args, execArgv) {
    // },
    /**
     * Gets executed just before initialising the webdriver session and test framework. It allows you
     * to manipulate configurations depending on the capability or spec.
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {Array.<String>} specs List of spec file paths that are to be run
     */
    // beforeSession: function (config, capabilities, specs) {
    // },
    /**
     * Gets executed before test execution begins. At this point you can access to all global
     * variables like `browser`. It is the perfect place to define custom commands.
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {Array.<String>} specs        List of spec file paths that are to be run
     * @param {Object}         browser      instance of created browser/device session
     */
    // before: function (capabilities, specs) {
    // },
    /**
     * Runs before a WebdriverIO command gets executed.
     * @param {String} commandName hook command name
     * @param {Array} args arguments that command would receive
     */
    // beforeCommand: function (commandName, args) {
    // },
    /**
     * Hook that gets executed before the suite starts
     * @param {Object} suite suite details
     */
    // beforeSuite: function (suite) {
    // },
    /**
     * Function to be executed before a test (in Mocha/Jasmine) starts.
     */
    // beforeTest: function (test, context) {
    // },
    /**
     * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
     * beforeEach in Mocha)
     */
    // beforeHook: function (test, context) {
    // },
    /**
     * Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
     * afterEach in Mocha)
     */
    // afterHook: function (test, context, { error, result, duration, passed, retries }) {
    // },
    /**
     * Function to be executed after a test (in Mocha/Jasmine).
     */
    // afterTest: function(test, context, { error, result, duration, passed, retries }) {
    // },


    /**
     * Hook that gets executed after the suite has ended
     * @param {Object} suite suite details
     */
    // afterSuite: function (suite) {
    // },
    /**
     * Runs after a WebdriverIO command gets executed
     * @param {String} commandName hook command name
     * @param {Array} args arguments that command would receive
     * @param {Number} result 0 - command success, 1 - command error
     * @param {Object} error error object if any
     */
    // afterCommand: function (commandName, args, result, error) {
    // },
    /**
     * Gets executed after all tests are done. You still have access to all global variables from
     * the test.
     * @param {Number} result 0 - test pass, 1 - test fail
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {Array.<String>} specs List of spec file paths that ran
     */
    // after: function (result, capabilities, specs) {
    // },
    /**
     * Gets executed right after terminating the webdriver session.
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {Array.<String>} specs List of spec file paths that ran
     */
    // afterSession: function (config, capabilities, specs) {
    // },
    /**
     * Gets executed after all workers got shut down and the process is about to exit. An error
     * thrown in the onComplete hook will result in the test run failing.
     * @param {Object} exitCode 0 - success, 1 - fail
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {<Object>} results object containing test results
     */
    // onComplete: function(exitCode, config, capabilities, results) {
    // },
    /**
    * Gets executed when a refresh happens.
    * @param {String} oldSessionId session ID of the old session
    * @param {String} newSessionId session ID of the new session
    */
    //onReload: function(oldSessionId, newSessionId) {
    //}
}

exports.config={
//
// ====================
//转轮配置
// ====================
//
//WebdriverIO允许它在任意位置(例如本地或本地)运行测试
//在远程机器上)。
跑步者:“本地”,
//
// ==================
//指定测试文件
// ==================
//定义应该运行哪些测试规范。模式与目录相关
//从中调用“wdio”。
//
//等级库定义为等级库文件数组(可选使用通配符)
//每个spec文件的测试将在单独的数据库中运行
//工作进程。以便在同一个工作进程中运行一组规范文件
//进程只需将它们包含在specs数组中的一个数组中。
//
//如果您是从NPM脚本调用“wdio”(请参阅https://docs.npmjs.com/cli/run-script),
//那么当前的工作目录就是`package.json`所在的位置,所以`wdio`
//将从那里被呼叫。
//
规格:[
“./测试/规范/*.ts”
],
//要排除的模式。
排除:[
//“路径/到/排除/文件”
],
//
// ============
//能力
// ============
//在此处定义您的功能。WebdriverIO可以同时运行多个功能
//根据功能的数量,WebdriverIO会启动几个测试
//会话。在您的能力范围内,您可以覆盖规范并排除中的选项
//将特定规格分组到特定功能。
//
//首先,您可以定义应该同时启动多少个实例
//假设你有3种不同的功能(Chrome、Firefox和Safari),你有
//将maxInstances设置为1;wdio将生成3个进程。因此,如果您有10个规范
//如果将maxInstances设置为10,则所有等级库文件将同时进行测试
//将生成30个进程。该属性将处理多少功能
//从同一测试中,应运行测试。
//
最大实例:10,
//
//如果您在整合所有重要功能时遇到困难,请查看
//Sauce Labs platform configurator—配置您的功能的绝佳工具:
// https://docs.saucelabs.com/reference/platforms-configurator
//
能力:[{
//每个功能都可以覆盖maxInstances
//网格中只有5个firefox实例可用,您可以确保
//一次启动5个实例。
最大实例:5,
//
browserName:“chrome”,
AcceptUnsecureCerts:正确
//如果提供outputDir,WebDrivero可以捕获驱动程序会话日志
//可以配置要包括/排除的日志类型。
//excludeDriverLogs:['*',//传递'*'以排除所有驱动程序会话日志
//excludeDriverLogs:['bugreport','server'],
}],
//
// ===================
//测试配置
// ===================
//在此处定义与WebdriverIO实例相关的所有选项
//
//日志详细程度:跟踪|调试|信息|警告|错误|静默
日志级别:“信息”,
//
//设置每个记录器的特定日志级别
//伐木工人:
//-webdriver,webdriverio
//-@wdio/applitools服务、@wdio/browserstack服务、@wdio/devtools服务、@wdio/sauce服务
//-@wdio/mocha框架,@wdio/jasmine框架
//-@wdio/本地跑步者
//-@wdio/消费新闻记者
//-@wdio/cli、@wdio/config、@wdio/sync、@wdio/utils
//日志详细程度:跟踪|调试|信息|警告|错误|静默
//日志级别:{
//webdriver:“信息”,
//“@wdio/applitools服务”:“信息”
// },
//
//如果您只想运行测试直到特定数量的测试失败,请使用
//保释(默认值为0-不保释,运行所有测试)。
保释金:0,
//
//设置基本URL以缩短URL命令调用。如果“URL”参数启动
//使用“/”,基本url将被加上前缀,而不包括基本url的路径部分。
//如果您的'url'参数在没有scheme或`/`(如'some/path`)的情况下启动,则基本url
//直接添加前缀。
baseUrl:'http://localhost',
//
//所有waitFor*命令的默认超时。
waitforTimeout:10000,
//
//请求的默认超时(毫秒)
//如果浏览器驱动程序或网格未发送响应
connectionRetryTimeout:120000,
//
//默认请求重试次数
connectionRetryCount:3,
//
//测试运行程序服务
//服务会接管你不想处理的特定工作。它们会增强
//您的测试设置几乎不费吹灰之力。与插件不同,它们不会添加新的
//相反,它们将自己连接到测试过程中。
服务:[“chromedriver”],
//您希望运行规范的框架。
//支持以下内容:摩卡咖啡、茉莉花和黄瓜
//另见:https://webdriver.io/docs/frameworks
//
//确保已安装特定框架的wdio适配器包
//在运行任何测试之前。
框架:“摩卡”,
//
//当整个specfile失败时重试整个specfile的次数
//specFileRetries:1,
//
//等级库文件重试尝试之间的延迟(秒)
//SpecFileRetriesDisplay:0,
//
//是否应立即重试specfiles或def
 npm install typescript ts-node --save-dev
{
    "compilerOptions": {
        "types": ["node", "webdriverio/sync", "@wdio/mocha-framework", "expect-webdriverio"]
    }
}
npm install @types/mocha