Yu Jia
Yu Jia

Reputation: 353

Cypress, got wrong result when use "Cypress.Commands.add" to defined a new command

I defined a new command in "commands.js"

Cypress.Commands.add('subValues', (a, b) => { return a - b });

then I call the new function use follwing code

it('Call new function', function(){
    let email = cy.subValues(15, 8);
    cy.get('#Email').type(email);   
});

but the result instead "7" the result is "[object Object]". enter image description here

what things I did wrong, please help!

Upvotes: 0

Views: 280

Answers (1)

maxwu
maxwu

Reputation: 432

To use the value from subject, please resolve it as below

cy.subValues(15, 8).then(x => cy.get('#Email').type(x));

Upvotes: 1

Related Questions