cypress |使用我在测试中添加的新命令失败



我已将此添加到命令文件:

Cypress.Commands.add("applyandSaveButtonsAreDisabled ", () => {
cy.get("[data-a-key=base-modal-button-Save]").should("be.disabled");
cy.get("[data-a-key=base-modal-button-Apply]").should("be.disabled");
});

但是当我尝试在测试中使用它时:

it("Test inital state of Login tab ", () => {
cy.get('[type="checkbox"]').check();
cy.applyandSaveButtonsAreDisabled();

失败,显示如下错误:

TypeError: cyp . applyandsavebuttonsaredisabled不是一个函数

我在这里做错了什么?我是否需要从我的测试文件中向命令文件添加一些引用?

在命令名的末尾有一个空格导致你的问题。

// will not work
Cypress.Commands.add("applyandSaveButtonsAreDisabled ", () => {
// use this
Cypress.Commands.add("applyandSaveButtonsAreDisabled", () => {

最新更新