簡體   English   中英

賽普拉斯不能在自定義命令中包含來自外部的值 in.get() function

[英]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>

但是當我想調用這個自定義命令時 - 我無法在 function 中提供任何參數。 在此處輸入圖像描述

您必須在 TypeScript 定義中為您的自定義命令定義所有參數:

// cypress>support>index.ts

testCommand(testVariable: string): Chainable<Element>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM