Search code examples
javascriptcucumbercypress

How to dynamically type text in Cypress


I want to enter dynamic text in cypress, so at each run, the name field will not have repeated input, for example name1, name 2...

So in the js file I would have something like

And("I enter a name", () => {
     portalPage.roleName().type("Cypress admin" + 1, { force: true })
})

Any help is appreciated.


Solution

  • If you are seeking random inputs, then lodash .random() will generate a random number from 0 to the input.

    // will generate random number between 0 and 9999
    portalPage.roleName().type(`Cypress admin${Cypress._.random(9999)}`, { force: true })