【问题标题】:Selenium with Apache Poi Save error messages in ExcelSelenium 与 Apache Poi 在 Excel 中保存错误消息
【发布时间】:2014-11-13 20:58:37
【问题描述】:
我有读取测试参数的 Excel 文件。
我想将测试期间出现的错误消息保存在同一个 Excel 文件中。我在 Excel 中创建了名为:“状态”的列。
我的带有错误消息的代码示例:
if((Konfiguration.get("some excel parametr").equalsIgnoreCase("metro"))) {
throw new RuntimeException("My error messages");
}
如何在 Excel 文件中的“状态”列中保存此错误消息
【问题讨论】:
标签:
java
excel
selenium
apache-poi
【解决方案1】:
写入 excel 文件中的特定列。
- 获取需要写入的列和行
- 在得到的列中写入数据。
如果您的行值为 2,列为 5,则使用 apache poi 打开您的 excel 并遍历您的特定单元格并写下您的消息。
FileInputStream file = new FileInputStream(new File(File_path));
HSSFWorkbook yourworkbook = new HSSFWorkbook(file);
HSSFSheet sheet1 = yourworkbook.getSheetAt(0);
Row row = sheet1.getRow(2);
Cell column = row.getCell(5);
column.setCellValue(your_error_message);
您还可以使用指针来跟踪您在上次写入期间写入的列。