javascript - cypress.io : Command namespacing, 链接

标签 javascript cypress

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

cy.entity.create(名称)

cy.entity.edit(id, 数据)

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");

关于javascript - cypress.io : Command namespacing, 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51553816/

相关文章:

loops - 如何验证我已从 Cypress 的表格中选择了正确的用户(html-table/angular-material)

node.js - 如何在 Cypress 中共享变量值

javascript - 在 Cypress 中获取原生 HTML 元素

cypress - Cypress :想部分模拟XHR响应

jquery - cy.get 返回无效的 jquery 元素

Javascript - 将对象的成员函数放在独立变量中?

javascript - 为什么我在 XSLT 转换期间出现此错误 : XSLT transformation failed?

javascript - javascript 中的 get.month() 返回二月份的错误输出

asp.net - 如何知道所有 AJAX 调用何时结束

JavaScript 长度和文本区域最大长度不匹配