cypress.io:命令命名空间,链接

cypress.io: Command namespacing, chaining

我已阅读 docs here,这接近我需要的,但不完全是。 我希望创建一个简单的命名空间,例如:

cy.entity.create(name)

cy.entity.edit(id, data)

cy.entity.delete(id)

以便我的 UI 测试在需要时直接 API 调用回退。 是否可以像这样以命名空间格式编写命令?

cy 是一个 Javascript 对象,因此如果您的目标只是将函数存储在 cy.entity 中,这将起作用:

cy.entity = {};
cy.entity.edit = (id, data) => {
    cy.log(`cy.entity.edit(${id}, ${data}) has been called`);
    // ...
}

// Then you can call cy.entity.edit() like this:
cy.entity.edit("test", "test");