use of com.xls.report.config.ElementLocator in project selenium_java by sergueik.
the class ReportData method createExcelFile.
// @SuppressWarnings("deprecation")
public static XSSFWorkbook createExcelFile(HashMap<String, Map<String, ArrayList<String>>> data) {
XSSFWorkbook book = new XSSFWorkbook();
XSSFCellStyle failCelStyle = book.createCellStyle();
XSSFCellStyle passCelStyle = book.createCellStyle();
// http://stackoverflow.com/questions/19145628/auto-size-height-for-rows-in-apache-poi
for (String sheetNameKey : data.keySet()) {
XSSFSheet sheet = book.createSheet(sheetNameKey);
XSSFRow row = ExcelConfiguration.CreateHeader(book, sheet, Configuration.header);
HashMap<String, ArrayList<String>> testMethods = (HashMap<String, ArrayList<String>>) data.get(sheetNameKey);
int l = 1;
for (String testMethod : testMethods.keySet()) {
passCelStyle.setFillForegroundColor(HSSFColor.BRIGHT_GREEN.index);
failCelStyle.setFillForegroundColor(HSSFColor.RED.index);
// XSSFColor myColor = new XSSFColor(XSSFColor.);
// failCelStyle.setFillForegroundColor(myColor);
// converting to poi 3.17
// passCelStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
passCelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// failCelStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
failCelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
row = sheet.createRow(l++);
XSSFCell cellName = row.createCell(Configuration.testNameIndex);
cellName.setCellValue(testMethod);
sheet.autoSizeColumn(Configuration.testNameIndex);
ArrayList<String> testData = testMethods.get(testMethod);
XSSFCell cellStatus = row.createCell(Configuration.testStatusIndex);
if ("fail".equalsIgnoreCase(testData.get(Configuration.testStatusIndex))) {
cellStatus.setCellStyle(failCelStyle);
cellStatus.setCellValue(testData.get(Configuration.testStatusIndex));
XSSFCell expCell = row.createCell(Configuration.exceptionMsgIndex);
expCell.setCellValue(testData.get(Configuration.exceptionMsgIndex));
sheet.autoSizeColumn(Configuration.exceptionMsgIndex);
XSSFCell exceptionTraceCell = row.createCell(Configuration.exceptionStackTrace);
exceptionTraceCell.setCellValue(testData.get(Configuration.exceptionStackTrace).trim());
sheet.autoSizeColumn(Configuration.exceptionStackTrace);
XSSFCell locatorCell = row.createCell(Configuration.locatorIndex);
String text = testData.get(Configuration.exceptionStackTrace).trim();
String jsonString = null;
Gson gson = new GsonBuilder().create();
int sIndex = text.indexOf('{');
int eIndex = text.indexOf('}');
jsonString = (sIndex == -1 || eIndex == -1) ? "" : text.substring(sIndex, (eIndex + 1));
ElementLocator locator = gson.fromJson(jsonString, ElementLocator.class);
locatorCell.setCellValue((locator == null) ? "" : locator.toString());
} else {
cellStatus.setCellStyle(passCelStyle);
cellStatus.setCellValue(testData.get(Configuration.testStatusIndex));
sheet.autoSizeColumn(Configuration.testStatusIndex);
XSSFCell expCell = row.createCell(Configuration.exceptionMsgIndex);
expCell.setCellValue(testData.get(Configuration.exceptionMsgIndex));
sheet.autoSizeColumn(Configuration.exceptionMsgIndex);
XSSFCell exceptionTraceCell = row.createCell(Configuration.exceptionStackTrace);
exceptionTraceCell.setCellValue(testData.get(Configuration.exceptionStackTrace).trim());
sheet.autoSizeColumn(Configuration.exceptionStackTrace);
}
}
}
return book;
}
Aggregations