0

I have a function that I want to add as a command so i can reuse it.

Its on cypress/support/commands.js:

Cypress.Commands.add("generatePassword", () => {

    return 'randomstring';
  }
);

Then on my test I want to use it as:

  it("Visits page", () => {

    const password = generatePassword();
    cy.log({password})
    // Here it logs this:
    //{password: {chainerid: chainer146, firstcall: false}}



  });

Any idea on how to get the actual value? Now i get this:

{chainerid: chainer146, firstcall: false}

Thanks.

2
  • 1
    Don't use a custom command in this situation, use a simple function. Commented Jun 10, 2020 at 17:54
  • but I cant import files. Commented Jun 11, 2020 at 7:34

1 Answer 1

1

Basically cypress works in promise chain and you're returning the promise chainerid from your custom command. You have to chain it to use in next statement. Use something like below.

it("Visits page", () => {
return cy.generatePassword().then(pwd => {
    cy.log(pwd);
  });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.