如何在 Cypress 中通过 TypeScript 项目使用 xpath 定位器?

问题描述 投票:0回答:2

最初,xpath 插件在我的 cypress 项目中运行良好。安装了 Typescript 插件并从 javascript 移至 Typescript。现在它开始在 xpath 上抛出错误

Property 'xpath' does not exist on type 'cy & EventEmitter'.ts(2339)

请建议,如何在 Cypress 项目中将 xpath 与 typescript 一起使用?

cypress-xpath": "^1.6.2",
包含在package.json中

package.json 文件如下:

"devDependencies": {
    "@types/node": "^14.17.8",
    "add": "^2.0.6",
    "cypress-cucumber-preprocessor": "^4.3.0",
    "cypress-mochawesome-reporter": "^2.2.0",
    "cypress-xpath": "^1.6.2",
    "typescript": "^4.4.3",
    "yarn": "^1.22.10"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
typescript xpath cypress cypress-cucumber-preprocessor
2个回答
9
投票

为此,您必须将其添加到您的

tsconfig.json
文件中。

{
  "compilerOptions": {
    "types": ["cypress", "cypress-xpath"]
  }
}

0
投票

在您使用的文件顶部添加引用类型将解决该问题

/// <reference types="cypress-xpath" />
© www.soinside.com 2019 - 2024. All rights reserved.