Closed tgoswami013 closed 9 months ago
If you're getting foo: undefined
then there is a problem with reading your csv, perhaps path is wrong?
You are right, something wrong with the csv file, I was getting undefined value for the first column test_case and value printed for remaining columns.
undefined value 11 foobar1 undefined value 22 foobar21 undefined value 33 foobar321 undefined value 44 foobar4321
Earlier I created csv using excel. Now, I pasted the same data to new csv file, which was created using visual studio code New File... option, and it is working fine.
value 1 value 11 foobar1 value 2 value 22 foobar21 value 3 value 33 foobar321 value 4 value 44 foobar4321
Thanks for helping :)
System info
Source code
https://playwright.dev/docs/test-parameterize#create-tests-via-a-csv-file
Above code is working for Playwright JavaScript but for TypeScript version getting Error: duplicate test title "foo: undefined"
CSV File test_case,some_value,some_other_value value 1,value 11,foobar1 value 2,value 22,foobar21 value 3,value 33,foobar321 value 4,value 44,foobar4321
TypeScript File
import fs from 'fs'; import path from 'path'; import { test } from '@playwright/test'; import { parse } from 'csv-parse/sync';
const records = parse(fs.readFileSync(path.join(__dirname, 'input.csv')), { columns: true, skip_empty_lines: true });
for (const record of records) { test(
foo: ${record.test_case}
, async ({ page }) => { console.log(record.test_case, record.some_value, record.some_other_value); }); }Expected
Error: duplicate test title "foo: undefined", first declared in file-handling/read-my-csv.spec.ts:12
Actual
Output CSV value in console