Cypress Randomize Data using Faker JS

Profile picture for user arilio666

Faker.js is a JavaScript utility that generates realistic false data for various uses such as testing, prototyping, and database populating. It offers a variety of data formats and ways for creating randomized data, such as names, addresses, phone numbers, dates, and more. Faker.js is a popular tool in web development projects for generating sample data for user interfaces and simulating real-world circumstances.


npm install --save-dev @faker-js/faker
  • Use the command to install faker.js onto the Cypress project.


import {faker} from '@faker-js/faker';
const email =
       console.log(`email: ${email}`)
  • For instance, this will generate a random email.
Cypress Randomize Data using Faker JS

We can see here it has generated an email.

export function createRandomUser(): User {
 return {
   userId: faker.datatype.uuid(),
   username: faker.internet.userName(),
   avatar: faker.image.avatar(),
   password: faker.internet.password(),
   registered at:,

Likewise, using the above methods, we can generate enough random names, emails, birthdates, etc.

import {faker} from '@faker-js/faker';
describe('Automating The Keypress Of Zero Site',()=> {
   it('visit the site ',()=>{
       var fakeNames = faker.internet.userName()

Here we can apply a random name inside the username field.

Cypress Randomize Data using Faker JS

Now we can see using faker.JS. We can do testing with random data with ease.