I am new to playwright, my CSV input file string contains comma and other symbol which is need to be considered as one string even though there are few comma in it, to be able to set as one string which is contains comma, I need to change from comma separator to pipe separator:
test_case|username|password
Account,Select,file.name.Test|ram|12345
Account,Select,Me,file.name.Test|sham|24680
Please help me - how to set CSV delimiter to pipe separator (|
) instead of comma (,
)?
import { test, expect } from '@playwright/test';
import fs from 'fs';
import path from 'path';
import { parse } from 'csv-parse/sync';
import assert from 'assert';
const records = parse(fs.readFileSync(path.join(__dirname, 'CSV.csv')), {
columns: true,
skip_empty_lines: true
});
for (const record of records){
test(`Test Case: ${record.test_case}`, async ({ page }) => {
//console.log(record.test_case, record.username, record.password);
}
Method readFileSync has option delimiter:
const records = parse(fs.readFileSync(path.join(__dirname, 'CSV.csv')), {
columns: true,
skip_empty_lines: true,
delimiter: '|'
});