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

use*_*083 4 xpath typescript cypress cypress-cucumber-preprocessor

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

Property 'xpath' does not exist on type 'cy & EventEmitter'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

请建议,如何在 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
  }
Run Code Online (Sandbox Code Playgroud)

Ala*_*Das 9

为此,您必须将其添加到您的tsconfig.json文件中。

{
  "compilerOptions": {
    "types": ["cypress", "cypress-xpath"]
  }
}
Run Code Online (Sandbox Code Playgroud)