![](/img/trans.png)
[英]TypeScript and Cypress can't return true/false in custom cypress command
[英]Cypress can't include value from outside in .get() function in custom command
我想在 Cypress 中創建一個自定義父命令,其中包含 get() function。 我需要從自定義命令外部提供元素的定位器。 這是我的代碼。
// cypress>support>commands.js Cypress.Commands.add('testCommand', (testVariable) => { cy.get(testVariable).click(); })
因為我使用的是 TypeScript 我需要在 index.ts 中添加命令
// cypress>support>index.ts testCommand(): Chainable<Element>
您必須在 TypeScript 定義中為您的自定義命令定義所有參數:
// cypress>support>index.ts
testCommand(testVariable: string): Chainable<Element>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.