Hello,
I am looking into running Playwright tests with data coming from JSON file in a for loop. I would like to run same tests for different product URLs that have different data which comes from the JSON file.
The problem -> Playwright doesn't recognize the array with data and doesn't run any tests in the for loop.
Any ideas on how can I solve this problem? Thanks!
This thread is trying to answer question "How can I run Playwright tests with data coming from a JSON file in a for loop?"
test.beforeEach(async () => {
console.log(before
);
const brand = envConfig().BASE_URL.match(/www.(.*?).c/)![1];
const urlsPath = ./util/urls/${brand}/${brand}.${envConfig().LOCALE}.json
;
plpURLsTest = JSON.parse(fs.readFileSync(urlsPath, 'utf-8'));
console.log(plpURLsTest = ${plpURLsTest}
);
});
for (let i = 0; i < plpURLsTest.length; i++) {
test.describe(Filter products on plp name
, () => {
test(@p0 Filter products ${i} on plp ${plpURLs[i]}
, async ({ page }) => {
await test.step(User navigates to the plp page
, async () => {
await page.goto(plpURLs[i].url);
});
});
});
}
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].