繁体   English   中英

如何让 command.js 和 index.d.ts 知道函数?

[英]How to make the function known by the command.js and index.d.ts?

我在 Cypress 中进行了这个测试,问题是它不会将任何值传递给 cypress.commands.add

命令.js:

Cypress.Commands.add('createCustomer', (customer) => {
    cy.wait(1000)
    cy.get('input[name="id"]').clear()
    cy.get('input[name="id"]').type(customer.cust_id)
    cy.wait(1000)
    cy.get('input[name="name"]').clear().type(customer.name);
})

索引.d.ts:

declare namespace Cypress {
    interface Chainable<Subject> {
        createCustomer(
            cust_id: string,
            name: string): Chainable<string>
    }
}

测试规范

describe('Create customer 1st', () => {
    it('first condition for customer', () => {
        cy.createCustomer('A0001', 'Chappy Rose') 
    })
})

似乎 test.spec.ts 没有将值传递给 commands.js。

请帮忙。 谢谢...

您在测试客户 id客户名称中传递两个参数,因此您的自定义命令应如下所示:

Cypress.Commands.add('createCustomer', (id, name) => {
    cy.wait(1000)
    cy.get('input[name="id"]').clear()
    cy.get('input[name="id"]').type(id)
    cy.wait(1000)
    cy.get('input[name="name"]').clear().type(name);
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM