如何在打字稿量角器中逐行读取csv文件?

How to read csv files line by line in typescript protractor?

我不知道如何使用打字稿在量角器中读取或写入 .csv 文件?

尝试 google 但没有成功。

就拿https://www.npmjs.com/package/csv

很遗憾,您不会自动拥有类型,您需要自己编写

尝试以下解决方案。 CSV 文件应包含 FirstName 和 LastName

import {browser} from 'protractor';
import * as path from 'path';
 describe('Protractor Typescript Demo', () => {
            it('CSV File Operations', async () => {
                const papa = require('papaparse');
                const fs = require('fs');
                const fileName = 'samplebook';
                const fileLocation: string = './resources/' + fileName + '.csv';
                console.log('Getting file path.....' + fileLocation);
                // Input Windows path fix, replace Windows specific '\' with '/' character after absolute resolution
                const absolutePath = await (path.resolve(__dirname, fileLocation)).replace(/\/g, '/');
                console.log('Geting absolute path....' + (path.resolve(__dirname)));
                const file = await fs.readFileSync  (absolutePath, 'utf8');
                const results = await papa.parse(file, {
                    header: true
                    //  delimiter: '>'
                });
                for (let i = 0; i < results.data.length - 1; i++) {
                    await readFromCSV.dataIteration(results.data[i]['Firstname'], results.data[i]['Lastname'], results.data[i]['Address']);
                }
            });
        });

        method called from different class///
         public async dataIteration(firstName: string, lastName: string, address?: string) {
                    console.log(firstName);
                    browser.waitForAngularEnabled(false);
                    await launchURL(); //custom methods*emphasized text*
                    await setFirstName(firstName);
                    await setLastName(lastName);
    }