Robot Framework和Selenium调用java方法

我devise了一个机器人脚本来testingSelenium的网页。

执行脚本后,Selenium将生成log.html和report.html,它提供了一些关于testing的反馈。 不过,我想输出像Excel格式。 我使用Java从apachefind了EXCEL库。

我如何收集信息并致电图书馆输出excel?

为了阅读Excel,你可以像这样使用 –

Open Excel {YourExcelFileName}.xls ${strColCount} = Get Column Count {YourExcelSheetName} ${strRowCount} = Get Row Count {YourExcelSheetName} :FOR ${rowIndex} IN RANGE 0 ${strRowCount} \ ${col1Val} Read Cell Data By Coordinates {YourExcelSheetName} 1 ${rowIndex} \ ${col2Val} Read Cell Data By Coordinates {YourExcelSheetName} 2 ${rowIndex} \ ${col3Val} Read Cell Data By Coordinates {YourExcelSheetName} 3 ${rowIndex} 

而对于写Excel,你可以使用Robot Framework提供的关键字“把string放到单元格中”

请在这里findRobot Framework提供的ExcelLibrary的更多细节

以下是使用POI和Java读取Excel的代码。 (确保你改变了文件名,path,包名等必需的东西)


 package sbps; import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.LinkedHashMap; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class del { public static void main(String a[]) { String strConnString = null; Connection con1 = null; String strQuery = null; String strFilePath = Driver.APP_PATH; HSSFWorkbook xlWBook; HSSFSheet xlSheet; HSSFRow xlRow,xlHeaderRow; HSSFCell xlCell; String strLogicalPath=""; String strColValue = ""; Statement st1 = null; ResultSet rs1 = null; String strGroups = null; String strExeVal = null; int intNumberOfColumns; String runOnBrowser = ""; String IEGroup = "", FFGroup = "", CHGroup = ""; boolean IEFlag = false, FFFlag = false, CHFlag = false; try { FileInputStream xlFile = new FileInputStream(new File(strFilePath+"\\05_TestCases\\GroupControlFiles.xls")); xlWBook = new HSSFWorkbook(xlFile); xlSheet = xlWBook.getSheet("Groups"); int rows = xlSheet.getPhysicalNumberOfRows(); int cols = xlSheet.getRow(0).getLastCellNum(); xlHeaderRow = xlSheet.getRow(0); Driver.APP_MAP = new LinkedHashMap<String, String>(); boolean blnFound=false; try { for(int i=1; i<=rows; ++i) { xlRow = xlSheet.getRow(i); runOnBrowser = ""; strGroups = xlRow.getCell((short)0).getStringCellValue(); strExeVal = xlRow.getCell((short)1).getStringCellValue(); if (!strExeVal.equalsIgnoreCase("null") && strExeVal.equalsIgnoreCase("YES")) { IEGroup = IEGroup + strGroups + ","; IEFlag = true; } strExeVal = xlRow.getCell((short)2).getStringCellValue(); if (!strExeVal.equalsIgnoreCase("null") && strExeVal.equalsIgnoreCase("YES")) { FFGroup = FFGroup + strGroups + ","; FFFlag = true; } strExeVal = xlRow.getCell((short)3).getStringCellValue(); if (!strExeVal.equalsIgnoreCase("null") && strExeVal.equalsIgnoreCase("YES")) { CHGroup = CHGroup + strGroups + ","; CHFlag = true; } // } } } catch(Exception ee) { } if (CHFlag) { CHGroup = CHGroup.substring(0, CHGroup.length() - 1); Driver.APP_MAP.put("CH", CHGroup); } if (IEFlag) { IEGroup = IEGroup.substring(0, IEGroup.length() - 1); Driver.APP_MAP.put("IE", IEGroup); } if (FFFlag) { FFGroup = FFGroup.substring(0, FFGroup.length() - 1); Driver.APP_MAP.put("FF", FFGroup); } xlFile.close(); } catch(Exception ee) { } } }