Cypress.Commands.add 不可分配给“keyof Chainable”类型的参数

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

我尝试遵循这个例子

https://docs.cypress.io/guides/end-to-end-testing/azure-active-directory-authentication 需要它来针对 Azure Active Directory 登录身份验证运行我的自动化 Cypress 测试

并陷入了这个问题

enter image description here

我在一个新项目中也尝试过使用不同版本的 cypress,结果相同

azure-active-directory automated-tests cypress
1个回答
0
投票

本页介绍自定义命令的类型如何为自定义命令提供类型支持。

向 cy 对象添加自定义命令时,您可以手动添加其类型以避免 TypeScript 错误。

创建类型定义文件

cypress/support/index.d.ts
。在其中添加类似的东西

declare global {
  namespace Cypress {
    interface Chainable {
      /**
       * Custom command to log in to AAD.
       * @example cy.loginToAAD(username, password)
       */
      loginToAAD(username: string, password: string): Chainable<void>
    }
  }
}

另外,在

tsconfig.json
中确保您的类型定义文件位于
types
路径中。

© www.soinside.com 2019 - 2024. All rights reserved.