Ejemplo n.º 1
0
        private static void CreateTestReport(string testPlanFile, TestPlanInfo testPlan)
        {
            var path = "TestsData\\Results\\{0}-Result-{1}.xls";

            var fi = new FileInfo(testPlanFile);
            var reportName = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
            TestingLogUtility.GenerateLogFile(String.Format(path, reportName, DateTime.Now.ToString("yyyyMMdd-hhmmss")), testPlan);
        }
Ejemplo n.º 2
0
        public static void GenerateLogFile(string logFile, TestPlanInfo planInfo)
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            ISheet sheet = wb.CreateSheet("TestResults");
            sheet.SetColumnWidth(0, 15 * 256);
            sheet.SetColumnWidth(1, 40 * 256);
            sheet.SetColumnWidth(2, 30 * 256);
            sheet.SetColumnWidth(3, 15 * 256);
            sheet.SetColumnWidth(4, 50 * 256);

            //set common cell styles
            ICellStyle styleHeader = wb.CreateCellStyle();
            IFont fontBold = wb.CreateFont();
            fontBold.Boldweight = (short)FontBoldWeight.Bold;
            fontBold.Color = NPOI.HSSF.Util.HSSFColor.White.Index;
            styleHeader.SetFont(fontBold);
            styleHeader.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SeaGreen.Index;
            styleHeader.FillPattern = FillPattern.SolidForeground;

            //pass
            ICellStyle stylePass = wb.CreateCellStyle();
            stylePass.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LightGreen.Index;
            stylePass.FillPattern = FillPattern.SolidForeground;

            //fail
            ICellStyle styleFail = wb.CreateCellStyle();
            styleFail.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
            styleFail.FillPattern = FillPattern.SolidForeground;

            //not executed
            ICellStyle styleNotExecuted = wb.CreateCellStyle();
            styleNotExecuted.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
            styleNotExecuted.FillPattern = FillPattern.SolidForeground;

            //title font
            IFont fontTitle = wb.CreateFont();
            fontTitle.Boldweight = (short)FontBoldWeight.Bold;
            fontTitle.FontHeightInPoints = 20;
            ICellStyle styleTitle = wb.CreateCellStyle();
            styleTitle.SetFont(fontTitle);

            //sub-title font
            IFont fontSubTitle = wb.CreateFont();
            fontSubTitle.Boldweight = (short)FontBoldWeight.Bold;
            fontSubTitle.FontHeightInPoints = 15;
            ICellStyle styleSubTitle = wb.CreateCellStyle();
            styleSubTitle.SetFont(fontSubTitle);

            int rowNumber = 0;

            //Add info regarding the Test Plan
            ICell cell;
            IRow row = sheet.CreateRow(rowNumber);
            cell = row.CreateCell(0);
            cell.SetCellValue(String.Format("Test Plan '{0}' - {1}", planInfo.Name, planInfo.Result? "Pass": "******"));
            cell.CellStyle = styleTitle;
            sheet.AddMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 4));

            foreach (var testCase in planInfo.TestCases)
            {
                rowNumber += 3;

                //Add info regarding the Test Case
                row = sheet.CreateRow(rowNumber);
                cell = row.CreateCell(0);
                cell.SetCellValue(String.Format("Test Case '{0}' - {1}", testCase.Name, testCase.Result? "Pass": "******"));
                cell.CellStyle = styleSubTitle;
                sheet.AddMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 4));

                //Add Header for Test Case Steps
                rowNumber++;
                row = sheet.CreateRow(rowNumber);

                cell = row.CreateCell(0);
                cell.SetCellValue("Step Number");
                cell.CellStyle = styleHeader;

                cell = row.CreateCell(1);
                cell.SetCellValue("Description");
                cell.CellStyle = styleHeader;

                cell = row.CreateCell(2);
                cell.SetCellValue("Keyword");
                cell.CellStyle = styleHeader;

                cell = row.CreateCell(3);
                cell.SetCellValue("Result");
                cell.CellStyle = styleHeader;

                cell = row.CreateCell(4);
                cell.SetCellValue("Error");
                cell.CellStyle = styleHeader;

                int stepNumber = 1;
                foreach (var step in testCase.Steps)
                {
                    //Add info regarding Test Case Step
                    rowNumber++;
                    row = sheet.CreateRow(rowNumber);
                    cell = row.CreateCell(0);
                    cell.SetCellValue(stepNumber.ToString());
                    //cell.CellStyle = step.Result >= 0 ? (step.Result > 0 ? stylePass : styleNotExecuted) : styleFail;

                    cell = row.CreateCell(1);
                    cell.SetCellValue(step.StepDescription);
                    //cell.CellStyle = step.Result >= 0 ? (step.Result > 0 ? stylePass : styleNotExecuted) : styleFail;

                    cell=row.CreateCell(2);
                    cell.SetCellValue(step.KeywordName);
                    //cell.CellStyle = step.Result >= 0 ? (step.Result > 0 ? stylePass : styleNotExecuted) : styleFail;

                    cell = row.CreateCell(3);
                    cell.SetCellValue(step.Result >= 0 ? (step.Result > 0 ? "Pass" : "Not Executed") : "Failed");
                    cell.CellStyle = step.Result >= 0 ? (step.Result > 0 ? stylePass : styleNotExecuted) : styleFail;

                    cell= row.CreateCell(4);
                    cell.SetCellValue(step.ErrorMessage);
                    //cell.CellStyle = step.Result >= 0 ? (step.Result > 0 ? stylePass : styleNotExecuted) : styleFail;

                    stepNumber++;
                }
            }

            using (var fileData = new FileStream(logFile, FileMode.Create, FileAccess.Write))
            {
                wb.Write(fileData);
            }
        }
Ejemplo n.º 3
0
        public static TestPlanInfo ReadTestPlan(string testPlanFile)
        {
            XSSFWorkbook xssfwb;
            using (FileStream file = new FileStream(testPlanFile, FileMode.Open, FileAccess.Read))
            {
                xssfwb = new XSSFWorkbook(file);
            }

            ISheet sheet = xssfwb.GetSheetAt(0); //get the first sheet

            var testPlan = new TestPlanInfo();
            var testCases = new List<TestCaseInfo>();

            //read the plan name
            var planName = sheet.GetRow(0).GetCell(1).ToString();
            testPlan.Name = planName;

            int row = 1;
            while (row <= sheet.LastRowNum)
            {
                if (sheet.GetRow(row) != null) //null is when the row only contains empty cells
                {
                    var firstCellValue = sheet.GetRow(row).GetCell(0) != null ? sheet.GetRow(row).GetCell(0).ToString() : "";

                    //test if it's a new test case
                    if (firstCellValue == "Test Case Name")
                    {
                        row++;
                        string testCaseName = sheet.GetRow(row).GetCell(0).StringCellValue;
                        string testCaseType = sheet.GetRow(row).GetCell(1) != null ? sheet.GetRow(row).GetCell(1).ToString() : "";
                        row++;
                        //get max cell number (based on the second row and the number of defined parameters
                        var maxCell = sheet.GetRow(row).LastCellNum;
                        row++; //skip the test case header row and the "Test Case Name" row

                        var steps = new List<TestCaseStepInfo>();
                        while (sheet.GetRow(row) != null)
                        {
                            if (sheet.GetRow(row).GetCell(1) != null && sheet.GetRow(row).GetCell(1).ToString() != String.Empty)
                            {
                                var descr = sheet.GetRow(row).GetCell(0) != null? sheet.GetRow(row).GetCell(0).ToString(): "";
                                var keywordName = sheet.GetRow(row).GetCell(1).ToString();
                                var keywordType = sheet.GetRow(row).GetCell(2) != null? sheet.GetRow(row).GetCell(2).ToString(): "";
                                var passCondition = sheet.GetRow(row).GetCell(3).ToString();
                                var failCondition = sheet.GetRow(row).GetCell(4).ToString();

                                var parameters = new List<string>();
                                for (int index = 5; index < maxCell; index++)
                                {
                                    var value = sheet.GetRow(row).GetCell(index) != null? sheet.GetRow(row).GetCell(index).ToString(): "";
                                    parameters.Add(value);
                                }

                                var step = new TestCaseStepInfo()
                                {
                                    StepDescription = descr,
                                    KeywordName = keywordName,
                                    KeywordType = keywordType,
                                    PassCondition = passCondition,
                                    FailCondition = failCondition,
                                    Parameters = parameters
                                };

                                steps.Add(step);
                            }

                            row++;
                        }

                        var testCase = new TestCaseInfo() { Name = testCaseName, Type = testCaseType, Steps = steps };
                        testCases.Add(testCase);
                    }
                }

                row++;
            }

            testPlan.TestCases = testCases;

            return testPlan;
        }