'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 1:[1]
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
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shankar |
