Java 使用Fillo如何读取所有行?
使用fillo,我已经设法使用fillo读取特定测试用例的数据。但我有一个需求,需要一次执行多个测试用例。所以根据要求读取所有行并将其作为键值对存储在哈希映射中 下面我将附上我的代码,我写的代码是为了阅读一个特定的测试用例,并放入哈希映射中Java 使用Fillo如何读取所有行?,java,excel,selenium,selenium-webdriver,automated-tests,Java,Excel,Selenium,Selenium Webdriver,Automated Tests,使用fillo,我已经设法使用fillo读取特定测试用例的数据。但我有一个需求,需要一次执行多个测试用例。所以根据要求读取所有行并将其作为键值对存储在哈希映射中 下面我将附上我的代码,我写的代码是为了阅读一个特定的测试用例,并放入哈希映射中 public HashMap<String, String> extractexcelData(String TestcaseID, String sheetname) throws Exception { HashMap
public HashMap<String, String> extractexcelData(String TestcaseID, String sheetname) throws Exception
{
HashMap<String, String> excelhashmapvalues = new HashMap<String, String>();
Connection connect = fillo.getConnection("src/test/resources/Datatable/MasterTestdata.xlsx");
String query = " Select * from " + sheetname + " where TestcaseID='" + TestcaseID + "'";
Recordset recordset = connect.executeQuery(query);
while(recordset.next())
{
ArrayList<String> collection = recordset.getFieldNames();
int size = collection.size();
for (i = 0; i <=(size-1); i++) {
String colname = collection.get(i);
String colval = recordset.getField(colname);
excelhashmapvalues.put(colname, colval);
}
}
recordset.close();
connect.close();
return excelhashmapvalues;
}
public HashMap extractexcelData(String TestcaseID,String sheetname)引发异常
{
HashMap excelhashmapvalues=新HashMap();
Connection connect=fillo.getConnection(“src/test/resources/Datatable/MasterTestdata.xlsx”);
String query=“从“+sheetname+”中选择*,其中TestcaseID=”+TestcaseID+”;
记录集记录集=connect.executeQuery(查询);
while(recordset.next())
{
ArrayList collection=recordset.getFieldNames();
int size=collection.size();
对于(i=0;i),您的问题是,当您处理下一个记录集时,您会覆盖映射中的值,因为您具有相同的列名
解决方案可能是将数据保留在地图列表中:
List<Map<String, String>> listOfMaps = new ArrayList<>();
while(recordset.next()) {
ArrayList<String> collection = recordset.getFieldNames();
int size = collection.size();
Map<String, String> values = new HashMap<>();
for (i = 0; i <=(size-1); i++) {
String colname = collection.get(i);
String colval = recordset.getField(colname);
values.put(colname, colval);
}
listOfMaps.add(values);
}
List listofmap=new ArrayList();
while(recordset.next()){
ArrayList collection=recordset.getFieldNames();
int size=collection.size();
映射值=新的HashMap();
对于(i=0;i
Map<String, List<String>> map = new HashMap<>();
while(recordset.next()) {
ArrayList<String> collection = recordset.getFieldNames();
int size = collection.size();
for (i = 0; i <=(size-1); i++) {
String colname = collection.get(i);
String colval = recordset.getField(colname);
map.computeIfAbsent(colname, k -> new ArrayList<>()).add(colval);
}
}