Search in sources :

Example 1 with ElementLocator

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;
}
Also used : HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) ElementLocator(com.xls.report.config.ElementLocator) Gson(com.google.gson.Gson) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ElementLocator (com.xls.report.config.ElementLocator)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1