Faker library is pre-installed and is available for calling inside of js snippets.
This approach is good when you need to generate data during execution of a test.
Fixtures are great for inserting data into database before tests are started, and cleaning up after tests are finished.
src/data-helpers/user.ts
Copy
import { faker } from '@faker-js/faker'import { APIClient } from './src/api-client'import { User } from './src/data-helpers/types'export async function createRandomUser(apiClient: APIClient, role: string): Promise<User> { const user: User = { userId: faker.string.uuid(), username: faker.internet.username(), email: faker.internet.email(), avatar: faker.image.avatar(), password: faker.internet.password(), birthdate: faker.date.birthdate(), registeredAt: faker.date.past(), role, }; // Insert user into database by using API of your app await apiClient.createUser(user) return user}