如何在javascript中存储信息表并检索相同的数据以进行验证?

问题描述

我有一个Excel数据,其大小作为行和列作为类别,并且价格是根据行和列的值计算的。 我不想从excel或其他外部文件获取数据,而是从另一个js文件获取数据。 我试图使用数据表存储值,但是我不断收到错误消息:

$(document).ready(function(){ ^

ReferenceError:未定义$

我试图使用类似对象,

pricetable = [
    ["size","category","price"],[1-50,C,500],[51-99,B,400],[100-199,A,300],],

那也不好。因此,有人可以帮助我解决如何存储和检索这些数据吗?

解决方法

请在我提供读写excel示例的地方使用此仓库

https://github.com/Bharath-Kumar-S/Read_Write_excel

我建议您从beforeAll挂钩中的Excel或Json文件中读取数据,并在整个测试过程中使用它。通过这种方式,您的脚本和数据得以分离。

const parser = require('simple-excel-to-json');
const doc = parser.parseXls2Json(`Sample.xlsx`);

doc[0].forEach((data,i) => {
    console.log(`${i} ${data.name} ${data.age}`)
})

enter image description here

enter image description here

在js对象中包含testdata

let priceTable = {
    size: [1 - 50,51 - 99,100 - 199],category: [`C`,`B`,`A`],price: [500,400,300]
}

priceTable.size.forEach((e,index)=>{
    console.log(`size ${e}`)
    console.log(`category ${priceTable.category[index]}`)
    console.log(`category ${priceTable.price[index]}`)
})

enter image description here