1

Pls say, How I can past only letters in my tests. Like this

    const uuid = () => Cypress._.random('^[A-Za-z]+$')
    const id = uuid()
    const firstname = `${id}`

    cy.get('.firstname').type(firstname)
Narine Poghosyan
  • 853
  • 3
  • 16
  • 26
  • Does this answer your question? [Generate random string/characters in JavaScript](https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript) – Aleksey L. Jul 16 '20 at 05:52
  • 1
    Or you could just use some library for generating random/fake data. For example https://github.com/marak/Faker.js/ – Aleksey L. Jul 16 '20 at 05:54
  • I see that answer, But Can I write with regexp, don't write all the letters? ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz – Narine Poghosyan Jul 16 '20 at 06:00

1 Answers1

0

⚠ If you want to generate UUIDs be aware that not all characters in a UUID are random: Read here on Wikipedia.


UUID

I personally use this small package to generate UUIDs


Chance.js

If you need more generated data for your tests I'd recommend chance.js. You can read more about generating UUIDs here chance.js/uuid


On your own

Generating UUIDs on your own was already answered in this mega thread here: How to create GUID / UUID?

If you don't care if some of the strings are duplicates of each other (e.g. for first names), you could just

const generate = () => {
  document.body.innerHTML = `${document.body.innerHTML} ${Math.random().toString(36).substring(2)}`;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button type="button" id="btn" onclick="generate()">
    Generate string
  </button>
</body>

</html>
DarkMikey
  • 383
  • 1
  • 4
  • 24