Exemple #1
0
        public string BuildStr(Dictionary <int, List <TestSuite> > tsDic)
        {
            for (int i = tsDic.Keys.Count; i > 1; i--)
            {
                foreach (TestSuite suite in tsDic[i])
                {
                    //TODO 存在测试套里面既有测试用例又有测试套的情况
                    string parenName = suite.NameHierarchy.ToArray()[i - 2];
                    string testStr   = string.Empty;
                    testStr = TestSuiteToStr(suite);

                    foreach (TestSuite testSuite in tsDic[i - 1])
                    {
                        if (parenName.Equals(testSuite.Name))
                        {
                            testSuite.TestLinkStr += testStr;
                            break;
                        }
                    }
                }
            }

            string resultStr = string.Empty;

            foreach (TestSuite testSuite in tsDic[1])
            {
                resultStr += this.TestSuiteToStr(testSuite);
            }
            ProgressBarShow.ShowProgressValue(100);
            return(resultStr);
        }
Exemple #2
0
        /// <summary>
        /// 测试用例转为Str
        /// </summary>
        /// <returns>List String</returns>
        private Dictionary <string, List <string> > CaseToStr()
        {
            Dictionary <string, List <string> > dicCase = new Dictionary <string, List <string> >();

            foreach (KeyValuePair <string, List <TestCase> > keyValuePair in _tcList)
            {
                OutputDisplay.ShowMessage($"【{keyValuePair.Key}】数据读取......", Color.MediumVioletRed);
                Dictionary <string, List <string> > suiteTc = new Dictionary <string, List <string> >();
                List <string> tcStrList = new List <string>();
                foreach (TestCase testCase in keyValuePair.Value)
                {
                    OutputDisplay.ShowMessage(testCase.Name, Color.Chartreuse);
                    ProgressBarShow.ShowProgressValue(keyValuePair.Value.IndexOf(testCase) * 100 / keyValuePair.Value.Count);
                    string fieldsStr = $"<node_order><![CDATA[{testCase.NodeOrder}]]></node_order>";
                    fieldsStr += $"<externalid><![CDATA[{testCase.ExternalId}]]></externalid>";
                    fieldsStr += $"<version><![CDATA[{testCase.Version}]]></version>";
                    fieldsStr += $"<summary><![CDATA[{testCase.Summary}]]></summary>";
                    fieldsStr += $"<preconditions><![CDATA[{testCase.Preconditions}]]></preconditions>";
                    fieldsStr += $"<execution_type><![CDATA[{testCase.ExecutionType.ToString()}]]></execution_type>";
                    fieldsStr += $"<importance><![CDATA[{testCase.Importance.ToString()}]]></importance>";
                    fieldsStr += $"<estimated_exec_duration>{testCase.EstimatedExecDuration}</estimated_exec_duration>";
                    fieldsStr += $"<status>{testCase.Status}</status>";
                    string tsStr = "";
                    foreach (TestStep testStep in testCase.TestSteps)
                    {
                        tsStr += "<step>";
                        tsStr += $"<step_number><![CDATA[{testStep.StepNumber}]]></step_number>";
                        tsStr += $"<actions><![CDATA[{testStep.Actions}]]></actions>";
                        tsStr += $"<expectedresults><![CDATA[{testStep.ExpectedResults}]]></expectedresults>";
                        tsStr += $"<execution_type><![CDATA[{testStep.ExecutionType}]]></execution_type>";
                        tsStr += "</step>";
                    }
                    fieldsStr += $"<steps>{tsStr}</steps>";
                    String keywordStr = $"<keywords>";
                    foreach (string keyword in testCase.Keywords)
                    {
                        keywordStr += $"<keyword name=\"{keyword}\"><notes><![CDATA[]]></notes></keyword>";
                    }
                    fieldsStr += keywordStr + "</keywords>";
                    string tcStr = $"<testcase name=\"{testCase.Name}\">{fieldsStr}</testcase>";
                    Thread.Sleep(50);
                    tcStrList.Add(tcStr);

                    string suitenames = string.Empty;
                    testCase.TestCaseHierarchy.ForEach(item => suitenames = suitenames + "|" + item);
                    if (!suiteTc.Keys.Contains(suitenames.TrimStart('|')))
                    {
                        suiteTc.Add(suitenames.TrimStart('|'), new List <string>());
                    }
                    suiteTc[suitenames.TrimStart('|')].Add(tcStr);
                }
                ProgressBarShow.ShowProgressValue(100);
                dicCase.Add(keyValuePair.Key, tcStrList);
            }

            return(dicCase);
        }
Exemple #3
0
        public List <TestCase> OutputTestCases()
        {
            List <TestCase> tcList = new List <TestCase>();

            foreach (XmlNode node in _sourceNodes)
            {
                tcList.Add(NodeToModel(node));
                ProgressBarShow.ShowProgressValue(this._sourceNodes.IndexOf(node) * 100 / (this._sourceNodes.Count - 1));
            }

            return(tcList);
        }
        private void WriteInWorkSheet(Excel.Workbook workBook)
        {
            var workSheet = (Excel.Worksheet)workBook.Worksheets.Item[1];

            int iFlag = 2;

            foreach (TestCase node in this._sourceTestCases)
            {
                if (node.Name == null && node.TestSteps == null)
                {
                    continue;
                }
                OutputDisplay.ShowMessage(node.Name, Color.Chartreuse);
                ProgressBarShow.ShowProgressValue(this._sourceTestCases.IndexOf(node) * 100 / this._sourceTestCases.Count);
                workSheet.Cells[iFlag, 1] = node.ExternalId;
                workSheet.Cells[iFlag, 2] = CommonHelper.DelTags(node.Name);
                string keywords = string.Empty;
                if (node.Keywords != null)
                {
                    foreach (string keyword in node.Keywords)
                    {
                        keywords = keywords + keyword + ",";
                    }
                }
                workSheet.Cells[iFlag, 3] = keywords.TrimEnd(',');
                workSheet.Cells[iFlag, 4] = node.Importance.ToString();
                workSheet.Cells[iFlag, 5] = node.ExecutionType.ToString();
                workSheet.Cells[iFlag, 6] = CommonHelper.DelTags(node.Summary);
                workSheet.Cells[iFlag, 7] = CommonHelper.DelTags(node.Preconditions);
                int iMerge = 0;

                if (node.TestSteps != null && node.TestSteps.Count != 0)
                {
                    foreach (var step in node.TestSteps)
                    {
                        workSheet.Cells[iFlag, 8] = CommonHelper.DelTags(step.Actions);
                        workSheet.Cells[iFlag, 9] = CommonHelper.DelTags(step.ExpectedResults);
                        iFlag++;
                        iMerge++;
                    }
                }
                else
                {
                    iFlag++;
                    iMerge++;
                }
                this.MergeCells(workSheet, iMerge, iFlag - iMerge);
                Thread.Sleep(50);
            }
            workSheet.Cells[iFlag++, 1] = "END";
            ProgressBarShow.ShowProgressValue(100);
        }
Exemple #5
0
        private string TestCaseToStr(TestCase tc)
        {
            Thread.Sleep(20);
            _allCases.Remove(tc);
            // 写文件时进行进度条展示
            ProgressBarShow.ShowProgressValue((_tcCount - _allCases.Count) * 100 / _tcCount);
            string fieldsStr = $"<node_order><![CDATA[{tc.NodeOrder}]]></node_order>";

            fieldsStr += $"<externalid><![CDATA[{tc.ExternalId}]]></externalid>";
            fieldsStr += $"<version><![CDATA[{tc.Version}]]></version>";
            fieldsStr += $"<summary><![CDATA[{tc.Summary}]]></summary>";
            fieldsStr += $"<preconditions><![CDATA[{tc.Preconditions}]]></preconditions>";
            fieldsStr += $"<execution_type><![CDATA[{tc.ExecutionType.ToString()}]]></execution_type>";
            fieldsStr += $"<importance><![CDATA[{tc.Importance.ToString()}]]></importance>";
            fieldsStr += $"<estimated_exec_duration>{tc.EstimatedExecDuration}</estimated_exec_duration>";
            fieldsStr += $"<status>{tc.Status}</status>";
            string tsStr = "";

            foreach (TestStep testStep in tc.TestSteps)
            {
                tsStr += "<step>";
                tsStr += $"<step_number><![CDATA[{testStep.StepNumber}]]></step_number>";
                tsStr += $"<actions><![CDATA[{testStep.Actions}]]></actions>";
                tsStr += $"<expectedresults><![CDATA[{testStep.ExpectedResults}]]></expectedresults>";
                tsStr += $"<execution_type><![CDATA[{testStep.ExecutionType}]]></execution_type>";
                tsStr += "</step>";
            }
            fieldsStr += $"<steps>{tsStr}</steps>";
            String keywordStr = $"<keywords>";

            foreach (string keyword in tc.Keywords)
            {
                keywordStr += $"<keyword name=\"{keyword}\"><notes><![CDATA[]]></notes></keyword>";
            }
            fieldsStr += keywordStr + "</keywords>";
            string tcStr = $"<testcase name=\"{tc.Name}\">{fieldsStr}</testcase>";

            return(tcStr);
        }
        private void WriteInWorkSheet(ExcelWorkbook workBook)
        {
            var workSheet = workBook.Worksheets.Add("MySheet");

            int maxHierarchy = 0;

            foreach (TestCase testCase in this._sourceTestCases)
            {
                if (maxHierarchy < testCase.TestCaseHierarchy.Count)
                {
                    maxHierarchy = testCase.TestCaseHierarchy.Count;
                }
            }

            BuildTemplate(workSheet, maxHierarchy);

            int iFlag = 2;

            foreach (TestCase node in this._sourceTestCases)
            {
                if (node.Name == null && node.TestSteps == null)
                {
                    continue;
                }
                OutputDisplay.ShowMessage(node.Name, Color.Chartreuse);
                ProgressBarShow.ShowProgressValue(this._sourceTestCases.IndexOf(node) * 100 / this._sourceTestCases.Count);
                workSheet.Cells[iFlag, 1].Value = node.ExternalId;

                for (int i = 0; i < node.TestCaseHierarchy.Count; i++)
                {
                    workSheet.Cells[iFlag, i + 2].Value = node.TestCaseHierarchy.ToArray()[i];
                }

                workSheet.Cells[iFlag, maxHierarchy + 2].Value = CommonHelper.DelTags(node.Name);
                string keywords = string.Empty;
                if (node.Keywords != null)
                {
                    foreach (string keyword in node.Keywords)
                    {
                        keywords = keywords + keyword + ",";
                    }
                }
                workSheet.Cells[iFlag, maxHierarchy + 3].Value = keywords.TrimEnd(',');
                workSheet.Cells[iFlag, maxHierarchy + 4].Value = node.Importance.ToString();
                workSheet.Cells[iFlag, maxHierarchy + 5].Value = node.ExecutionType.ToString();
                workSheet.Cells[iFlag, maxHierarchy + 6].Value = CommonHelper.DelTags(node.Summary);
                workSheet.Cells[iFlag, maxHierarchy + 7].Value = CommonHelper.DelTags(node.Preconditions);
                int iMerge = 0;

                if (node.TestSteps != null && node.TestSteps.Count != 0)
                {
                    foreach (var step in node.TestSteps)
                    {
                        workSheet.Cells[iFlag, maxHierarchy + 8].Value = CommonHelper.DelTags(step.Actions);
                        workSheet.Cells[iFlag, maxHierarchy + 9].Value = CommonHelper.DelTags(step.ExpectedResults);
                        iFlag++;
                        iMerge++;
                    }
                }
                else
                {
                    iFlag++;
                    iMerge++;
                }
                this.MergeCells(workSheet, iMerge, iFlag - iMerge, maxHierarchy + 9);
                Thread.Sleep(50);
            }
            workSheet.Cells[iFlag++, 1].Value = "END";
            ProgressBarShow.ShowProgressValue(100);
        }
Exemple #7
0
        private void WriteInWorkSheet(ExcelWorkbook workBook)
        {
            var workSheet = workBook.Worksheets.Add("MySheet");

            int maxHierarchy = 0;

            foreach (TestCase testCase in this._sourceTestCases)
            {
                if (maxHierarchy < testCase.TestCaseHierarchy.Count)
                {
                    maxHierarchy = testCase.TestCaseHierarchy.Count;
                }
            }

            BuildTemplate(workSheet, maxHierarchy);

            int iFlag = 2;

            foreach (TestCase node in this._sourceTestCases)
            {
                if (node.Name == null && node.TestSteps == null)
                {
                    continue;
                }
                // 写Excel时进度条展示
                // ProgressBarShow.ShowProgressValue(this._sourceTestCases.IndexOf(node) * 100 / this._sourceTestCases.Count);
                workSheet.Row(iFlag).CustomHeight = true;
                workSheet.Cells[iFlag, 1].Value   = node.ExternalId;

                for (int i = 0; i < node.TestCaseHierarchy.Count; i++)
                {
                    workSheet.Cells[iFlag, i + 2].Value = node.TestCaseHierarchy.ToArray()[i];
                }

                workSheet.Cells[iFlag, maxHierarchy + 2].Value = CommonHelper.DelTags(node.Name);
                string keywords = string.Empty;
                if (node.Keywords != null)
                {
                    foreach (string keyword in node.Keywords)
                    {
                        keywords = keywords + keyword + Environment.NewLine;
                    }
                }
                workSheet.Cells[iFlag, maxHierarchy + 3].Value = keywords.TrimEnd((char[])"\n\r".ToCharArray());
                workSheet.Cells[iFlag, maxHierarchy + 4].Value = node.Importance.ToString();
                workSheet.Cells[iFlag, maxHierarchy + 5].Value = node.ExecutionType.ToString();

                if (this._isShowStepsNo)
                {
                    workSheet.Cells[iFlag, maxHierarchy + 6].Value = CommonHelper.GenerateNoByLineBreak(node.Summary);
                    workSheet.Cells[iFlag, maxHierarchy + 7].Value = CommonHelper.GenerateNoByLineBreak(node.Preconditions);
                }
                else
                {
                    workSheet.Cells[iFlag, maxHierarchy + 6].Value = CommonHelper.DelTags(node.Summary);
                    workSheet.Cells[iFlag, maxHierarchy + 7].Value = CommonHelper.DelTags(node.Preconditions);
                }

                int iMerge = 0;

                if (node.TestSteps != null && node.TestSteps.Count != 0)
                {
                    foreach (var step in node.TestSteps)
                    {
                        string stepNo = string.Empty;
                        if (this._isShowStepsNo)
                        {
                            stepNo = $"{node.TestSteps.IndexOf(step) + 1}、";
                        }

                        workSheet.Cells[iFlag, maxHierarchy + 8].Value = $"{stepNo}{CommonHelper.DelTags(step.Actions)}";
                        workSheet.Cells[iFlag, maxHierarchy + 9].Value = $"{stepNo}{CommonHelper.DelTags(step.ExpectedResults)}";

                        iFlag++;
                        iMerge++;
                    }
                }
                else
                {
                    iFlag++;
                    iMerge++;
                }
                MergeCells(workSheet, iMerge, iFlag - iMerge, maxHierarchy + 9);
                Thread.Sleep(50);
            }
            workSheet.Cells[iFlag, 1].Value = "END";
            ProgressBarShow.ShowProgressValue(100);
        }
        public List <TestCase> GetExcelSheetData(ExcelWorksheet eWorksheet)
        {
            List <TestCase> tcList = new List <TestCase>();
            int             usedRows, usedCols;

            if (eWorksheet.Dimension == null)
            {
                this._logger.Warn(new Exception("No TestCase, this Sheet is new!"));
                return(new List <TestCase>());
            }
            else
            {
                usedRows = eWorksheet.Dimension.End.Row;
                usedCols = eWorksheet.Dimension.End.Column;
            }

            if (usedRows == 0 || usedRows == 1)
            {
                this._logger.Warn(new Exception("No TestCase!"));
                return(tcList);
            }

            for (int i = 1; i < eWorksheet.Dimension.End.Row; i++)
            {
                if (eWorksheet.Cells[i, 1].Value != null || eWorksheet.Cells[i, 1].Text != string.Empty ||
                    !eWorksheet.Cells[i, 1].Text.Equals("END"))
                {
                    continue;
                }
                usedRows = i;
                break;
            }

            TestCase tc = new TestCase();

            for (int i = 2; i <= usedRows; i++)
            {
                ProgressBarShow.ShowProgressValue(i * 100 / usedRows);
                var currentCell = eWorksheet.Cells[i, 1];
                if (currentCell.Text.Equals("END"))
                {
                    continue;
                }

                //设置单元格格式为文本格式,防止为自定义格式时读取单元格报错
                for (int j = 2; j <= usedCols; j++)
                {
                    eWorksheet.Cells[i, j].Style.Numberformat.Format = "@";
                }

                if (currentCell.Value == null)
                {
                    TestStep ts = new TestStep
                    {
                        StepNumber      = tc.TestSteps.Count + 1,
                        ExecutionType   = ExecType.手动,
                        Actions         = eWorksheet.Cells[i, usedCols - 1].Text,
                        ExpectedResults = eWorksheet.Cells[i, usedCols].Text
                    };

                    tc.TestSteps.Add(ts);
                    continue;
                }
                else
                {
                    List <string> testSuitesName = new List <string>();
                    if (usedCols > 9)
                    {
                        for (int j = 1; j <= usedCols - 9; j++)
                        {
                            if (eWorksheet.Cells[i, j + 1].Value != null)
                            {
                                testSuitesName.Add(eWorksheet.Cells[i, j + 1].Text);
                            }
                        }
                    }

                    tc = new TestCase
                    {
                        ExternalId        = string.Format($"{currentCell.Text}_{new Random().Next(0, 10000)}"),
                        TestCaseHierarchy = testSuitesName,
                        Name          = eWorksheet.Cells[i, usedCols - 7].Text,
                        Keywords      = eWorksheet.Cells[i, usedCols - 6].Text.Split(',').ToList(),
                        Importance    = CommonHelper.StrToImportanceType(eWorksheet.Cells[i, usedCols - 5].Text),
                        ExecutionType = CommonHelper.StrToExecType(eWorksheet.Cells[i, usedCols - 4].Text),
                        Summary       = eWorksheet.Cells[i, usedCols - 3].Text,
                        Preconditions = eWorksheet.Cells[i, usedCols - 2].Text
                    };

                    TestStep tsOne = new TestStep
                    {
                        StepNumber      = 1,
                        ExecutionType   = ExecType.手动,
                        Actions         = eWorksheet.Cells[i, usedCols - 1].Text.ToString(),
                        ExpectedResults = eWorksheet.Cells[i, usedCols].Text.ToString()
                    };

                    tc.TestSteps = new List <TestStep> {
                        tsOne
                    };
                    OutputDisplay.ShowMessage(tc.Name, Color.Chartreuse);

                    if (tc.ExternalId != null)
                    {
                        tcList.Add(tc);
                    }
                }
            }

            return(tcList);
        }