示例#1
0
        /// <summary>
        /// get main task case count(just main but not Include the goto case)
        /// </summary>
        /// <param name="startNode">start Node</param>
        /// <returns>count</returns>
        public static int GetCount(CaseCell startNode)
        {
            int nowCount = 0;
            List <CaseLoopCountInfo> nowLoops = new List <CaseLoopCountInfo>();

            while (startNode != null)
            {
                if (startNode.CaseType == CaseType.Case)
                {
                    nowCount++;
                }
                else if (startNode.CaseType == CaseType.Repeat)
                {
                    if (startNode.IsHasChild)
                    {
                        myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(startNode.CaseXmlNode);
                        nowLoops.Add(new CaseLoopCountInfo(startNode.ChildCells[0], tempProjectLoadInfo.times));
                    }
                }
                else if (startNode.CaseType == CaseType.Project)
                {
                    if (startNode.IsHasChild)
                    {
                        startNode = startNode.ChildCells[0];
                    }
                    continue;
                }
                startNode = startNode.NextCell;
            }
            while (nowLoops.Count != 0)
            {
                startNode = nowLoops[nowLoops.Count - 1].LoopNode;
                int tempRate = nowLoops[nowLoops.Count - 1].CaseRate;
                nowLoops.Remove(nowLoops[nowLoops.Count - 1]);
                while (startNode != null)
                {
                    if (startNode.CaseType == CaseType.Case)
                    {
                        nowCount += tempRate;
                    }
                    else if (startNode.CaseType == CaseType.Repeat)
                    {
                        if (startNode.IsHasChild)
                        {
                            myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(startNode.CaseXmlNode);
                            nowLoops.Add(new CaseLoopCountInfo(startNode.ChildCells[0], tempProjectLoadInfo.times * tempRate));
                        }
                    }
                    startNode = startNode.NextCell;
                }
            }
            return(nowCount);
        }
示例#2
0
        /// <summary>
        /// i will get the csae info that you need to show in your Tree(使用MyRunCaseData的重载版本针对不同执行协议对content的内容有优化)
        /// </summary>
        /// <param name="runCaseData">MyRunCaseData</param>
        /// <returns>the info with myCaseLaodInfo</returns>
        public static myCaseLaodInfo GetCaseLoadInfo(MyRunCaseData <ICaseExecutionContent> runCaseData)
        {
            myCaseLaodInfo myInfo = new myCaseLaodInfo("NULL");

            myInfo.id       = runCaseData.id;
            myInfo.remark   = runCaseData.name;
            myInfo.caseType = CaseType.Case;
            myInfo.content  = runCaseData.testContent.MyExecutionContent == null?string.Format("> {0}", runCaseData.testContent.MyExecutionTarget) : string.Format("> {0}{1}{2}", runCaseData.testContent.MyExecutionTarget, MyConfiguration.CaseShowTargetAndContent, runCaseData.testContent.MyExecutionContent);

            myInfo.caseProtocol = runCaseData.testContent.MyCaseProtocol;
            if (runCaseData.actions != null)
            {
                foreach (var tempAction in runCaseData.actions)
                {
                    myInfo.actions.Add(tempAction.Key, tempAction.Value.caseAction);
                }
            }
            return(myInfo);
        }
示例#3
0
        private bool AnalysisXmlCase(string myCasePath, CaseActionActuator caseActuator, Hashtable checkDataHt, bool isWithSouseXml, out string errorMessage, out List <string> loadErrorList)
        {
            bool tempIsScriptRunTimeDeal = false;

            errorMessage  = null;
            loadErrorList = new List <string>();
            CaseFileXmlAnalysis xmlAnalysis = new CaseFileXmlAnalysis();

            if (caseActuator == null)
            {
                return(false);
            }
            if (caseActuator.Runstate != CaseActuatorState.Stop)
            {
                errorMessage = "The TestCase not stop";
                return(false);
            }
            if (!File.Exists(myCasePath))
            {
                errorMessage = "用例文件不存在,请重新选择";
                return(false);
            }
            if (!xmlAnalysis.LoadFile(myCasePath))
            {
                errorMessage = "该脚本数据格式错误,请修正错误。详情请查看错误日志";
                return(false);
            }

            XmlNodeList myCaseProject = xmlAnalysis.xml.ChildNodes[1].ChildNodes;

            #region check case data
            if (checkDataHt != null)
            {
                foreach (DictionaryEntry de in checkDataHt)
                {
                    string tempStr = CaseTool.CheckCase(xmlAnalysis.xml.ChildNodes[1], (string)de.Key, (string[])de.Value);
                    if (tempStr != "")
                    {
                        errorMessage = tempStr;
                        return(false);
                    }
                }
            }
            #endregion

            Dictionary <int, Dictionary <int, CaseCell> > myProjectCaseDictionary = new Dictionary <int, Dictionary <int, CaseCell> >();

            caseActuator.DisconnectExecutionDevice();
            caseActuator.Dispose();

            ProjctCollection myProjctCollection = new ProjctCollection();
            try
            {
                #region Project analyze

                foreach (XmlNode tempNode in myCaseProject)
                {
                    myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(tempNode);
                    string         thisErrorTitle      = "Project ID:" + tempProjectLoadInfo.id;
                    if (tempProjectLoadInfo.ErrorMessage != "")
                    {
                        loadErrorList.Add(string.Format("【{1}】:{0}", tempProjectLoadInfo.ErrorMessage, thisErrorTitle));
                    }
                    if (tempProjectLoadInfo.caseType == CaseType.ScriptRunTime)
                    {
                        //deal with ScriptRunTime
                        if (!tempIsScriptRunTimeDeal)
                        {
                            caseActuator.LoadScriptRunTime(tempNode);
                            tempIsScriptRunTimeDeal = true;
                        }
                        else
                        {
                            thisErrorTitle = "ScriptRunTime";
                            loadErrorList.Add(string.Format("【{1}】:{0}", "find another ScriptRunTime ,ScriptRunTime is unique so it will be skip", thisErrorTitle));
                        }
                        continue;
                    }
                    if (tempProjectLoadInfo.caseType != CaseType.Project)
                    {
                        loadErrorList.Add(string.Format("【{1}】:{0}", "not legal Project ,it will be skip", "legal"));
                        continue;
                    }

                    #region deal this Project

                    CaseCell tempProjctCell = new CaseCell(tempProjectLoadInfo.caseType, tempNode, null);
                    myProjctCollection.Add(tempProjctCell);

                    Dictionary <int, CaseCell> tempCaseDictionary = new Dictionary <int, CaseCell>();
                    if (myProjectCaseDictionary.ContainsKey(tempProjectLoadInfo.id))
                    {
                        loadErrorList.Add(string.Format("【{1}】:{0}", "find the same project id in this file ,it will make [Goto] abnormal", thisErrorTitle));
                    }
                    else
                    {
                        myProjectCaseDictionary.Add(tempProjectLoadInfo.id, tempCaseDictionary);
                    }

                    //myTargetCaseList 将包含当前project或repeat集合元素
                    List <KeyValuePair <CaseCell, XmlNode> > myTargetCaseList = new List <KeyValuePair <CaseCell, XmlNode> >();
                    myTargetCaseList.Add(new KeyValuePair <CaseCell, XmlNode>(tempProjctCell, tempNode));
                    while (myTargetCaseList.Count > 0)
                    {
                        //Case analyze
                        foreach (XmlNode tempChildNode in myTargetCaseList[0].Value)
                        {
                            //load Show Info
                            myCaseLaodInfo tempCaseLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(tempChildNode);
                            thisErrorTitle = "Case ID:" + tempCaseLoadInfo.id;
                            if (tempCaseLoadInfo.ErrorMessage != "")
                            {
                                loadErrorList.Add(string.Format("【{1}】:{0}", tempCaseLoadInfo.ErrorMessage, thisErrorTitle));
                                loadErrorList.Add(string.Format("【{1}】:{0}", "this error can not be repair so drop it", thisErrorTitle));
                            }
                            else
                            {
                                if (tempCaseLoadInfo.caseType == CaseType.Case)
                                {
                                    //load Run Data
                                    var tempCaseRunData = MyCaseScriptAnalysisEngine.GetCaseRunData(tempChildNode);
                                    if (tempCaseRunData.errorMessages != null)
                                    {
                                        foreach (string tempErrorMes in tempCaseRunData.errorMessages)
                                        {
                                            loadErrorList.Add(string.Format("【{1}】:{0}", tempErrorMes, thisErrorTitle));
                                        }
                                    }
                                    CaseCell tempChildCell = new CaseCell(tempCaseLoadInfo.caseType, tempChildNode, tempCaseRunData);
                                    if (tempCaseDictionary.ContainsKey(tempCaseLoadInfo.id))
                                    {
                                        loadErrorList.Add(string.Format("【{1}】:{0}", "find the same case id in this project ,it will make [Goto] abnormal", thisErrorTitle));
                                    }
                                    else
                                    {
                                        tempCaseDictionary.Add(tempCaseLoadInfo.id, tempChildCell);
                                    }
                                    myTargetCaseList[0].Key.Add(tempChildCell);
                                }
                                else if (tempCaseLoadInfo.caseType == CaseType.Repeat)
                                {
                                    CaseCell tempChildCell = new CaseCell(tempCaseLoadInfo.caseType, tempChildNode, null);

                                    myTargetCaseList[0].Key.Add(tempChildCell);
                                    myTargetCaseList.Add(new KeyValuePair <CaseCell, XmlNode>(tempChildCell, tempChildNode));
                                }
                                else
                                {
                                    //it will cant be project and if it is unknow i will not show it
                                    loadErrorList.Add(string.Format("【{1}】:{0}", "find unkown case so drop it", thisErrorTitle));
                                }
                            }
                        }
                        myTargetCaseList.Remove(myTargetCaseList[0]);
                    }
                    #endregion
                }
                #endregion

                if (!tempIsScriptRunTimeDeal)
                {
                    loadErrorList.Add(string.Format("【{1}】:{0}", "ScriptRunTime is not find ", "ScriptRunTime"));
                    errorMessage = "ScriptRunTime is not find ,the case will cannot run";
                    return(false);
                }
                else
                {
                    caseActuator.SetCaseRunTime(myProjectCaseDictionary, myProjctCollection);
                    //启动数据呈现
                    return(true);
                }
            }
            //严重错误
            catch (Exception ex)
            {
                ErrorLog.PutInLog(ex);
                errorMessage = ex.Message;
                caseActuator.DisconnectExecutionDevice();
                caseActuator.Dispose();
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// i will get the csae info that you need to show in your Tree (对于CASE 的content 仅供参考)
        /// </summary>
        /// <param name="sourceNode">source Node</param>
        /// <returns>the info with myCaseLaodInfo</returns>
        public static myCaseLaodInfo GetCaseLoadInfo(XmlNode sourceNode)
        {
            myCaseLaodInfo myInfo = new myCaseLaodInfo("NULL");

            switch (sourceNode.Name)
            {
                #region Project show info
            case "Project":
                //Type
                myInfo.caseType = CaseType.Project;
                //name
                if (sourceNode.Attributes["name"] == null)
                {
                    myInfo.name = "not find";
                }
                else
                {
                    myInfo.name = sourceNode.Attributes["name"].Value;
                }
                //remark
                if (sourceNode.Attributes["remark"] == null)
                {
                    myInfo.remark = "not find";
                }
                else
                {
                    myInfo.remark = sourceNode.Attributes["remark"].Value;
                }
                //id
                if (sourceNode.Attributes["id"] == null)
                {
                    myInfo.ErrorMessage = "not find the ID";
                }
                else
                {
                    try
                    {
                        myInfo.id = int.Parse(sourceNode.Attributes["id"].Value);
                    }
                    catch (Exception ex)
                    {
                        myInfo.ErrorMessage = ex.Message;
                    }
                }
                break;
                #endregion

                #region Case show info
            case "Case":
                //Type
                myInfo.caseType = CaseType.Case;
                //remark
                if (sourceNode.Attributes["remark"] == null)
                {
                    myInfo.remark = "not find";
                }
                else
                {
                    myInfo.remark = sourceNode.Attributes["remark"].Value;
                }
                //id
                if (sourceNode.Attributes["id"] == null)
                {
                    myInfo.ErrorMessage = "not find the ID";
                }
                else
                {
                    try
                    {
                        myInfo.id = int.Parse(sourceNode.Attributes["id"].Value);
                    }
                    catch (Exception ex)
                    {
                        myInfo.ErrorMessage = "Analytical ID Fial" + ex.Message;
                    }
                }
                //case cantent and caseProtocol
                XmlNode tempCaseContent = sourceNode.SelectSingleNode("Content");
                if (tempCaseContent == null)
                {
                    myInfo.ErrorMessage = "can not find Content";
                }
                else
                {
                    try
                    {
                        myInfo.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), tempCaseContent.Attributes["protocol"].Value);
                    }
                    catch
                    {
                        myInfo.caseProtocol = CaseProtocol.unknownProtocol;
                        myInfo.ErrorMessage = "";
                    }

                    if (tempCaseContent.HasChildNodes)
                    {
                        string tempTarget = CaseTool.GetXmlAttributeVauleEx(tempCaseContent.ChildNodes[0], "target", null);
                        if (tempTarget == null)
                        {
                            myInfo.content = " > " + tempCaseContent.ChildNodes[0].InnerText;
                        }
                        else
                        {
                            myInfo.content = " > " + tempTarget + MyConfiguration.CaseShowTargetAndContent + tempCaseContent.ChildNodes[0].InnerText;
                        }
                    }
                    else
                    {
                        myInfo.ErrorMessage = "can not find [ContentData] TestData";
                    }
                }
                //case action
                XmlNode tempCaseAction = sourceNode.SelectSingleNode("Action");
                if (tempCaseAction != null)
                {
                    if (tempCaseAction.SelectSingleNode("Pass") != null)
                    {
                        /*
                         * if (tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value != null)
                         * {
                         *  switch (tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value)
                         *  {
                         *
                         *  }
                         * }
                         */
                        CaseAction tempAction;
                        try
                        {
                            tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value);
                        }
                        catch
                        {
                            tempAction = CaseAction.action_unknow;
                        }
                        myInfo.actions.Add(CaseResult.Pass, tempAction);
                    }
                    if (tempCaseAction.SelectSingleNode("Fail") != null)
                    {
                        CaseAction tempAction;
                        try
                        {
                            tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value);
                        }
                        catch
                        {
                            tempAction = CaseAction.action_unknow;
                        }
                        myInfo.actions.Add(CaseResult.Fail, tempAction);
                    }
                }
                break;
                #endregion

                #region Repeat show info
            case "Repeat":
                //Type
                myInfo.caseType = CaseType.Repeat;
                //remark
                if (sourceNode.Attributes["remark"] == null)
                {
                    myInfo.remark = "not find";
                }
                else
                {
                    myInfo.remark = sourceNode.Attributes["remark"].Value;
                }
                //times
                if (sourceNode.Attributes["times"] == null)
                {
                    myInfo.ErrorMessage = "not find the Times";
                }
                else
                {
                    try
                    {
                        myInfo.times = int.Parse(sourceNode.Attributes["times"].Value);
                    }
                    catch (Exception ex)
                    {
                        myInfo.ErrorMessage = "Analytical Repeat Times Fial" + ex.Message;
                    }
                }
                break;
                #endregion

            case "ScriptRunTime":
                myInfo.caseType = CaseType.ScriptRunTime;
                break;

            default:
                //unkonw CASE;
                break;
            }
            return(myInfo);
        }
示例#5
0
        /// <summary>
        /// i will get the next myTreeTagInfo in my queue
        /// </summary>
        /// <returns>the CaseCell you want</returns>
        public CaseCell nextCase()
        {
            if (nowCaseNode == null) //起始节点
            {
                nowCaseNode = startCaseNode;
                if (nowCaseNode.CaseType == CaseType.Repeat)
                {
                    if (nowCaseNode.IsHasChild)
                    {
                        myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(nowCaseNode.CaseXmlNode);
                        AddCaseLoop(nowCaseNode.ChildCells[0], tempProjectLoadInfo.times);
                    }
                    return(nextCase());
                }
                else if (nowCaseNode.CaseType == CaseType.Case)
                {
                    queueNowCount++;
                    return(nowCaseNode);
                }
                else if (nowCaseNode.CaseType == CaseType.Project)
                {
                    if (nowCaseNode.IsHasChild)
                    {
                        startCaseNode = nowCaseNode.ChildCells[0];
                        nowCaseNode   = null;
                        return(nextCase());
                    }
                    return(null); //空Project
                }
                else
                {
                    return(null); //当前设计不会有这种情况
                }
            }
            else
            {
                if (myCaseLoopList.Count > 0)
                {
                    int      tempNowListIndex     = myCaseLoopList.Count - 1;
                    CaseCell tempNextLoopTreeNode = myCaseLoopList[tempNowListIndex].nextCase();
                    if (tempNextLoopTreeNode == null)
                    {
                        DelCaseLoop(myCaseLoopList[tempNowListIndex]);
                        return(nextCase());
                    }
                    else
                    {
                        if (tempNextLoopTreeNode.CaseType == CaseType.Repeat)
                        {
                            if (tempNextLoopTreeNode.IsHasChild)
                            {
                                myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(tempNextLoopTreeNode.CaseXmlNode);
                                AddCaseLoop(tempNextLoopTreeNode.ChildCells[0], tempProjectLoadInfo.times);
                            }

                            return(nextCase());
                        }
                        else if (tempNextLoopTreeNode.CaseType == CaseType.Case)
                        {
                            queueNowCount++;
                            return(tempNextLoopTreeNode);
                        }
                        else
                        {
                            return(null); //当前设计不会有这种情况
                        }
                    }
                }
                else
                {
                    if (nowCaseNode.NextCell == null)
                    {
                        return(null); //当前 【Queue】 结束
                    }
                    else
                    {
                        nowCaseNode = nowCaseNode.NextCell;
                        if (nowCaseNode.CaseType == CaseType.Repeat)
                        {
                            if (nowCaseNode.IsHasChild)
                            {
                                myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(nowCaseNode.CaseXmlNode);
                                AddCaseLoop(nowCaseNode.ChildCells[0], tempProjectLoadInfo.times);
                            }

                            return(nextCase());
                        }
                        else if (nowCaseNode.CaseType == CaseType.Case)
                        {
                            queueNowCount++;
                            return(nowCaseNode);
                        }
                        else
                        {
                            return(null); //当前设计不会有这种情况
                        }
                    }
                }
            }
        }