Home > Software engineering >  Trying to write a Cypress UI test that uses a passed string
Trying to write a Cypress UI test that uses a passed string

Time:05-11

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
  });

CodePudding user response:

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
});
  • Related