0
0
Cypresstesting~10 mins

Dynamic test data generation in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to generate a random email for testing.

Cypress
const randomEmail = `user$[1]@example.com`;
Drag options to blanks, or click blank then click option'
AMath.random().toString(36).substring(2, 10)
BDate.now()
Cnew Date()
DMath.floor(Math.random())
Attempts:
3 left
💡 Hint
Common Mistakes
Using Date.now() alone may cause collisions if tests run quickly.
Using new Date() returns an object, not a string.
Math.floor(Math.random()) always returns 0.
2fill in blank
medium

Complete the code to create a random username with a prefix.

Cypress
const username = `user_$[1]`;
Drag options to blanks, or click blank then click option'
AMath.random()
BMath.floor(Math.random() * 10000)
CDate.now()
Dnew Date().getTime()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.random() alone returns a decimal, not suitable for usernames.
Using Date.now() or getTime() may cause long numbers.
3fill in blank
hard

Fix the error in the code to generate a random password of length 8.

Cypress
const password = Array.from({ length: 8 }, () => [1]).join('');
Drag options to blanks, or click blank then click option'
AMath.random().toString(36).charAt(8)
BMath.random().toString(36).charAt(0)
CMath.random().toString(36).charAt(10)
DMath.random().toString(36).charAt(2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using charAt(0) returns '0' always.
Using charAt(10) or charAt(8) may return empty string.
4fill in blank
hard

Fill both blanks to create a dynamic test user object with random id and email.

Cypress
const testUser = { id: [1], email: `test$[2]@mail.com` };
Drag options to blanks, or click blank then click option'
AMath.floor(Math.random() * 1000)
BMath.random()
CDate.now()
DMath.random().toString(36).substring(2, 8)
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.random() directly for id gives a decimal.
Using Date.now() for email part creates long numbers.
5fill in blank
hard

Fill all three blanks to generate a dynamic test data object with username, password, and email.

Cypress
const testData = { username: `user$[1]`, password: Array.from({ length: 6 }, () => [2]).join(''), email: `email$[3]@test.com` };
Drag options to blanks, or click blank then click option'
AMath.floor(Math.random() * 5000)
BMath.random().toString(36).charAt(2)
CMath.random().toString(36).substring(2, 6)
DDate.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.random() directly for username causes decimals.
Using charAt(0) for password returns '0' always.
Using Date.now() for email part creates long numbers.