如何在typescript量角器中逐行读取csv文件?
我不知道如何用typescript在量角器中读取或写入.csv文件 试着用谷歌搜索,但没有成功。就这样吧如何在typescript量角器中逐行读取csv文件?,typescript,protractor,Typescript,Protractor,我不知道如何用typescript在量角器中读取或写入.csv文件 试着用谷歌搜索,但没有成功。就这样吧 不幸的是,您将不会自动生成类型,您需要编写自己的尝试下面的解决方案。CSV文件应具有cols FirstName和LastName import {browser} from 'protractor'; import * as path from 'path'; describe('Protractor Typescript Demo', () => { it
不幸的是,您将不会自动生成类型,您需要编写自己的尝试下面的解决方案。CSV文件应具有cols 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);
}
从“量角器”导入{browser};
从“路径”导入*作为路径;
描述('量角器类型脚本演示',()=>{
它('CSV文件操作',异步()=>{
const papa=require('papaparse');
常数fs=要求('fs');
常量文件名='samplebook';
constfilelocation:string='./resources/'+fileName+'.csv';
log('获取文件路径…'+文件位置);
//输入Windows路径修复,在绝对分辨率后用“/”字符替换Windows特定的“\”
const absolutePath=wait(path.resolve(\uu dirname,fileLocation)).replace(/\\\\/g,“/”);
log('Geting绝对路径…'+(path.resolve(_dirname));
const file=wait fs.readFileSync(绝对路径,'utf8');
const results=wait papa.parse(文件{
标题:true
//分隔符:'>'
});
for(设i=0;i
正如我看到的,这是Jasmin和Java脚本,最初的问题是关于typescript。