我是新的剧作家,我的CSV输入文件字符串包含逗号和其他符号,这是需要被视为一个字符串,即使有几个逗号在它,能够设置为一个字符串,这是包含逗号,我需要从逗号分隔符改为管道分隔符:
test_case|username|password
Account,Select,file.name.Test|ram|12345
Account,Select,Me,file.name.Test|sham|24680
请帮助我-如何将CSV分隔符设置为管道分隔符(|
)而不是逗号(,
)?
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);
}
1条答案
按热度按时间f0brbegy1#
方法readFileSync具有选项分隔符: