In this article, we will see how we can run tests from a CSV file in playwright. Here is the CSV file we will be working with today, which contains some URLs of sites, and we will visit them.

const { test } = require('@playwright/test');
const fs = require("fs");
var links = fs.readFileSync("CSV\\Book1.csv")
.toString()
.split('\n')
.map(e => e.trim())
for (const link of links) {
test('test for ' + link.toString(), async ({ page }) => {
console.log(link);
await page.goto(link);
});
}
- First, we are reading the CSV file from the path, cleaning, trimming, and reading the buffer of each line.
- We iterate the links variable using an advanced for loop wrapped around the test.
- We then added the link variable, which was iterated to the test step to avoid duplicate test name errors.
- Then the link variable was passed into the goto method of the playwright, which will now visit all the sites with their respective name with different tests.


Fri, 12/16/2022 - 10:51
Hi , I need some help to verify data from database in playwright .
- Log in or register to post comments
Permalink