I have a normal object in which I use a faker to generate random values:
const product = {
id: faker.random.numeric(6),
note: faker.random.word(),
};
I have two tests that have a step that takes this object as an argument
test('Populate form', async ({
dashboardPage,
page,
}) => {
await dashboardPage.createNewProduct(product);
await expect(page).toHaveScreenshot();
});
The problem is that the data generated in this object during the run of these tests is random only for one test, while for the second it will be the same as for the first. What is the problem and how can it be solved?
I tried to generate this object using a synchronous function, but that didn't help either
function generateNewData() {
return {
id: faker.random.numeric(6),
note: faker.random.word(),
}
};
test('Populate form', async ({
dashboardPage,
page,
}) => {
const product = generateNewData();
await dashboardPage.createNewProduct(product);
await expect(page).toHaveScreenshot();
});
Perhaps something like the below could work. If it does not work perhaps your faker initialization is not working correctly.