I got this test in Cypress, the problem is that it won't pass any values to the 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')
})
})
It seems that test.spec.ts does not pass the values to the commands.js.
Please help. Thanks...
You are passing two parameters in your test customer id and customer name, so your custom command should be like this :
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);
})