Home > front end >  How to insert String variable into the String inside cy.get()
How to insert String variable into the String inside cy.get()

Time:11-05

I am using Cypress with Typescript and es6:

enter image description here

and I have defined const inside a test:

const folderName = "Test"

I tried to insert that folderName into the String inside cy.get() using String Substitution according to this enter image description here

I managed to have it working by doing this:

cy.get('[name="folder-name-'   folderName   '"]').next().click({force: true})

But I think there are cleaner ways to do it. What am I missing here?

CodePudding user response:

You're looking for Template literals (Template string). It is used with backticks.

Your code should be:

cy.get(`[name="folder-name-${folderName}"]`).next().click({force: true})
  • Related