Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to write a Cypress UI test that uses a passed string

I’m attempting to write a Cypress test that uses a string passed through by a different function.
The other function simply calls the cypress function and passes a string.
This seems to be possible from what I’ve seen in documentation but I can’t figure out what I’m missing.
The Cypress test is just supposed to find a button based on it’s title, defined by the passed string and click said button.

  When('I click the button ""', function (string) {
    // Clicks a button that test defines by title
    cy.get('button[title=${string}]').click
  });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I see you are using single quote instead of backtick for string interpolation. If it’s not a typo you need to correct that

When('I click the button ""', function (string) {
  // Clicks a button that test defines by title
  cy.get(`button[title=${string}]`).click
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading