microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.47k stars 3.56k forks source link

[BUG] [TypeScript] Duplicate Title Error While reading CSV in for loop #28464

Closed tgoswami013 closed 9 months ago

tgoswami013 commented 9 months ago

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

MindaugasMateika commented 9 months ago

If you're getting foo: undefined then there is a problem with reading your csv, perhaps path is wrong?

tgoswami013 commented 9 months ago

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 :)