Exemple #1
0
        public static void addNewScrpit(this M_testCase mtc)
        {
            string caseString = "<TestCase desc=\"" + mtc.Name + "\" ><Step name=\"R_InitStep\" desc=\"这是一个初始步骤\">" +
                                "<ParamBinding name=\"waitTime\" value=\"\" /></Step></TestCase>";

            mtc.testXML = caseString;
        }
        /// <summary>
        /// 创建场景
        /// </summary>
        public static void creatScene(Stream MS, int DemandID, string name)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            M_runScene mrs = new M_runScene();

            mrs.DemandID  = DemandID;
            mrs.name      = name;
            mrs.creatDate = DateTime.Now;
            QC_DB.M_runScene.Add(mrs);



            HSSFWorkbook hssfworkbook = new HSSFWorkbook(MS);


            HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(hssfworkbook);

            //eva.EvaluateInCell(cell);//取结果不取公式
            eva.EvaluateAll();//取结果不取公式

            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            rows.MoveNext();



            while (rows.MoveNext())
            {
                IRow   row       = (IRow)rows.Current;
                string sheetName = row.GetCell(1).ToString();
                if (sheetName == null || sheetName.Trim() == "")
                {
                    break;
                }

                ISheet caseSheet = hssfworkbook.GetSheet(sheetName);

                //找不到相关案例的话直接下一条
                int        ID  = Convert.ToInt32(caseSheet.SheetName);
                M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }

                var rts = getRunScript <M_runTestCase>(mtc, caseSheet, mrs.ID);
                QC_DB.M_runTestCase.AddRange(rts);
            }

            QC_DB.SaveChanges();
        }
        public static List <tmp_TaskScript> tmpTaskScript(Stream MS)
        {
            List <tmp_TaskScript> result = new List <tmp_TaskScript>();

            HSSFWorkbook hssfworkbook = new HSSFWorkbook(MS);


            HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(hssfworkbook);

            //eva.EvaluateInCell(cell);//取结果不取公式
            eva.EvaluateAll();//取结果不取公式

            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            rows.MoveNext();



            QCTESTEntities QC_DB = new QCTESTEntities();

            while (rows.MoveNext())
            {
                IRow   row       = (IRow)rows.Current;
                string sheetName = row.GetCell(1).ToString();
                if (sheetName == null || sheetName.Trim() == "")
                {
                    break;
                }

                ISheet caseSheet = hssfworkbook.GetSheet(sheetName);

                //找不到相关案例的话直接下一条
                int        ID  = Convert.ToInt32(caseSheet.SheetName);
                M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }

                var rts = getRunScript <tmp_TaskScript>(mtc, caseSheet);
                QC_DB.tmp_TaskScript.AddRange(rts);
                result.AddRange(rts);
            }

            QC_DB.SaveChanges();

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 保存来自json的脚本编辑
        /// </summary>
        /// <param name="steps">json数据 只有steps</param>
        public static void editScript(this M_testCase mtc, string steps)
        {
            XElement caseXml = XElement.Parse(mtc.testXML);

            caseXml.Nodes().Remove();

            XElement xx = testCaseHelper.json2StepList(steps);

            foreach (var step in xx.DescendantNodes())
            {
                caseXml.Add(step);
            }

            mtc.testXML = caseXml.ToString();
        }
Exemple #5
0
        /// <summary>
        /// 获得场景Excel
        /// </summary>
        /// <param name="_tnc"></param>
        /// <returns></returns>
        public static MemoryStream getSceneExcelMS(List <int> ids)
        {
            HSSFWorkbook hssfworkbook = ExcelHelper.InitializeWorkbook();

            ISheet config = hssfworkbook.CreateSheet("配置表");

            IRow  row   = config.CreateRow(0);
            ICell cell0 = row.CreateCell(0);

            cell0.SetCellValue("案例名");

            ICell cell1 = row.CreateCell(1);

            cell1.SetCellValue("案例ID");

            ICell cell2 = row.CreateCell(2);

            cell2.SetCellValue("参数数量");

            config.SetColumnWidth(0, 30 * 256);

            QCTESTEntities QC_DB = new QCTESTEntities();

            foreach (int id in ids)
            {
                M_testCase mtc = (from t in QC_DB.M_testCase
                                  where t.ID == id
                                  select t).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }
                var pdl = XElement.Parse(mtc.testXML).ParamDictionary();
                ExcelHelper.creatCaseSheet(hssfworkbook, pdl, mtc.ID.ToString(), mtc.Name);

                //name要做处理?
                ExcelHelper.creatConfigRow(config, mtc.Name, mtc.ID.ToString(), pdl.Count);
            }

            MemoryStream ms = new MemoryStream();

            hssfworkbook.Write(ms);

            return(ms);
        }
Exemple #6
0
        /// <summary>
        /// 获取真实的执行案例
        /// </summary>
        /// <param name="param">参数表</param>
        /// <returns></returns>
        public static XElement getRunScript(this M_testCase mtc, Dictionary <string, string> param)
        {
            XElement testCase = XElement.Parse(mtc.testXML);

            return(testCase.getRunScript(param));
        }
Exemple #7
0
        /// <summary>
        /// 创建执行案例
        /// </summary>
        /// <param name="sheet">sheet页</param>
        /// <param name="sceneID">场景ID</param>
        private static void insertRunCase(QCTESTEntities QC_DB, ISheet sheet, int sceneID)
        {
            int ID = Convert.ToInt32(sheet.SheetName);

            M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();

            if (mtc == null)
            {
                return;
            }



            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            //读取下一行
            rows.MoveNext();//如果没有要处理下
            IRow headRow = (IRow)rows.Current;



            Dictionary <string, string> data = new Dictionary <string, string>();
            List <string> keys = new List <string>();

            //首先获得参数列表
            for (int i = 1; i < headRow.LastCellNum; i++)
            {
                ICell cell = headRow.GetCell(i);
                if (cell == null || cell.ToString() == "")
                {
                    break;                                       //有空数据直接退出
                }
                string key = cell.ToString();
                data.Add(key, "");
                keys.Add(key);
            }

            //逐行转化案例
            while (rows.MoveNext())
            {
                IRow row = (IRow)rows.Current;
                if (row.GetCell(0) == null || row.GetCell(0).StringCellValue.Trim() == "")
                {
                    break;                                                                       //案例名字没有退出
                }
                string caseName = row.GetCell(0).StringCellValue;
                if (caseName.Length > 50)
                {
                    caseName = caseName.Substring(0, 50);
                }
                XElement cloneXML = XElement.Parse(mtc.testXML);
                cloneXML.SetAttributeValue("name", caseName);//name

                for (int i = 1; i < keys.Count; i++)
                {
                    ICell  cell  = row.GetCell(i);
                    string value = "";
                    if (cell != null)
                    {
                        //cell = eva.EvaluateInCell(cell);
                        cell.SetCellType(CellType.String);
                        value = cell.StringCellValue;
                    }
                    data[keys[i]] = value;
                }



                //获得最终案例
                cloneXML.getRunScript(data);

                //放入数据库

                M_runTestCase mrtc = new M_runTestCase();
                mrtc.sceneID = sceneID;
                mrtc.testXML = cloneXML.ToString();
                mrtc.name    = caseName;
                QC_DB.M_runTestCase.Add(mrtc);
            }
        }
        private static List <T> getRunScript <T>(M_testCase mtc, ISheet sheet, int sceneID = 0)
            where T : class
        {
            List <T> result = new List <T>();


            int ID = Convert.ToInt32(sheet.SheetName);


            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            //读取下一行
            rows.MoveNext();//如果没有要处理下
            IRow headRow = (IRow)rows.Current;



            Dictionary <string, string> data = new Dictionary <string, string>();
            List <string> keys = new List <string>();

            //首先获得参数列表
            for (int i = 1; i < headRow.LastCellNum; i++)
            {
                ICell cell = headRow.GetCell(i);
                if (cell == null || cell.ToString() == "")
                {
                    break;                                       //有空数据直接退出
                }
                string key = cell.ToString();
                data.Add(key, "");
                keys.Add(key);
            }

            //逐行转化案例
            while (rows.MoveNext())
            {
                IRow row = (IRow)rows.Current;
                if (row.GetCell(0) == null || row.GetCell(0).StringCellValue.Trim() == "")
                {
                    break;                                                                       //案例名字没有退出
                }
                string caseName = row.GetCell(0).StringCellValue;
                if (caseName.Length > 50)
                {
                    caseName = caseName.Substring(0, 50);
                }
                XElement cloneXML = XElement.Parse(mtc.testXML);
                cloneXML.SetAttributeValue("name", caseName);//name

                for (int i = 0; i < keys.Count; i++)
                {
                    ICell  cell  = row.GetCell(i + 1);
                    string value = "";
                    if (cell != null)
                    {
                        //cell = eva.EvaluateInCell(cell);
                        cell.SetCellType(CellType.String);
                        value = cell.StringCellValue;
                    }
                    data[keys[i]] = value;
                }


                //获得最终案例
                cloneXML.getRunScript(data);

                if (typeof(T) == typeof(M_runTestCase))
                {
                    M_runTestCase mrtc = new M_runTestCase();
                    mrtc.sceneID = sceneID;
                    mrtc.testXML = cloneXML.ToString();
                    mrtc.name    = caseName;
                    result.Add(mrtc as T);
                }
                else if (typeof(T) == typeof(tmp_TaskScript))
                {
                    tmp_TaskScript mrtc = new tmp_TaskScript();
                    mrtc.title  = caseName;
                    mrtc.script = cloneXML.ToString();
                    result.Add(mrtc as T);
                }
            }
            return(result);
        }