如何让 command.js 和 index.d.ts 知道函数?
How to make the function known by the command.js and index.d.ts?
我在 Cypress 中进行了这个测试,问题是它不会将任何值传递给 cypress.commands.add
Commands.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);
})
Index.d.ts:
declare namespace Cypress {
interface Chainable<Subject> {
createCustomer(
cust_id: string,
name: string): Chainable<string>
}
}
Test.spec.ts
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);
})
我在 Cypress 中进行了这个测试,问题是它不会将任何值传递给 cypress.commands.add
Commands.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);
})
Index.d.ts:
declare namespace Cypress {
interface Chainable<Subject> {
createCustomer(
cust_id: string,
name: string): Chainable<string>
}
}
Test.spec.ts
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);
})