Пример #1
0
        private static IElement searchElement(string name, string screenName, ListUIElements elementsAndIndicator)
        {
            List <IElement>       elements  = elementsAndIndicator.Elements;
            ListElementsIndicator indicator = elementsAndIndicator.Indicator;

            return(DoSearchElement(name, screenName, elements, indicator == ListElementsIndicator.OnlyRootElements));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="classExpression"></param>
        /// <param name="projectPath"></param>
        /// <param name="name_space"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns>relative file path</returns>
        private string GenerateClassExpScripts(ClassExpression classExpression, string projectPath, string name_space,
                                               ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            if (classExpression.getName() == null || classExpression.getListFunction() == null ||
                classExpression.getListFunction().Count <= 0)
            {
                return(null);
            }
            string functionsScripts = "";

            foreach (FunctionExpression func in classExpression.getListFunction())
            {
                if (functionsScripts != "")
                {
                    functionsScripts += NEW_LINE;
                }
                functionsScripts += GenerateFunctionExpScripts(func, listUIElements, mapAliasWithNode, myLog, instanceName);
            }
            // create new file
            string classContent = GetTemplateUCClassContent()
                                  //.Replace(GLOBAL_REPLACE, "") disabled by @duongtd 05/29
                                  .Replace(CLASS_REPLACE, classExpression.getName())
                                  .Replace(CONTENT_REPLACE, functionsScripts);
            string filePath            = Path.Combine(classExpression.GetCorrectWorkspace(), classExpression.getName() + ".cs");
            string fileContentTemplate = GetTemplateRunCsFileContent()
                                         .Replace(NAMESPACE_REPLACE, name_space);

            CreateNewFile(fileContentTemplate, classContent, Path.Combine(projectPath, filePath));
            return(filePath);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapClassFunc">(classname, list of functions)</param>
        private List <string> GenerateAdditionScripts(Dictionary <string, List <FunctionExpression> > mapClassFunc, string projectPath,
                                                      string name_space, ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            List <string> listRelativeFilePath = new List <string>();
            string        fileContentTemplate  = GetTemplateRunCsFileContent()
                                                 .Replace(NAMESPACE_REPLACE, name_space);

            foreach (var pair in mapClassFunc)
            {
                string className = pair.Key;
                List <FunctionExpression> listFunctions = pair.Value;
                string functionsScripts = "";
                foreach (FunctionExpression func in listFunctions)
                {
                    if (functionsScripts != "")
                    {
                        functionsScripts += NEW_LINE;
                    }
                    functionsScripts += GenerateFunctionExpScripts(func, listUIElements, mapAliasWithNode, myLog, instanceName);
                }
                // create new file
                string classContent = GetTemplateUCClassContent()
                                      //.Replace(GLOBAL_REPLACE, "") modified by @duong 05/29
                                      .Replace(CLASS_REPLACE, className)
                                      .Replace(CONTENT_REPLACE, functionsScripts);
                string filePath = Path.Combine("UserCode", className + ".cs");
                listRelativeFilePath.Add(filePath);
                CreateNewFile(fileContentTemplate, classContent, Path.Combine(projectPath, filePath));
            }
            return(listRelativeFilePath);
        }
Пример #4
0
        private SpecNode parseNode(string expression, ListUIElements elementsAndIndicator,
                                   Dictionary <string, string> mappingAlias, MyLog myLog)
        {
            /**
             * determine if Delay
             */
            if (Regex.IsMatch(expression, AbstractSpecUserAction.DELAY_TITLE_EXPRESSION))
            {
                return(new SpecNode(expression));
            }

            /**
             * determine if Wait
             */
            if (Regex.IsMatch(expression, AbstractSpecUserAction.PRE_WAIT + "(_\\d*)*") ||
                Regex.IsMatch(expression, AbstractSpecUserAction.POST_WAIT + "(_\\d*)*"))
            {
                return(new SpecNode(expression));
            }

            /**
             * determine if Keyboard
             */
            if (Regex.IsMatch(expression, AbstractSpecUserAction.KEYBOARD_PRESS_REGEX))
            {
                return(new SpecNode(expression));
            }

            /**
             * determine if Result
             */
            if (Regex.IsMatch(expression, AbstractSpecUserAction.RESULT))
            {
                return(new SpecNode(expression));
            }

            /**
             * determine if UserCode
             */
            if (Regex.IsMatch(expression, AbstractSpecUserAction.USER_CODE))
            {
                return(new SpecNode(expression));
            }
            if (Regex.IsMatch(expression, AbstractSpecUserAction.USER_CODE_WITH_VARIABLE_DECLARE))
            {
                return(new SpecNode(expression));
            }
            Tuple <IElement, string> pair =
                parseNodeAndAttribute(expression, elementsAndIndicator, mappingAlias, myLog);

            if (pair == null)
            {
                return(null);
            }
            return(new SpecNode(pair.Item1, pair.Item2, expression));
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pairSheet"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private TestSpecificationScreen parsePairSheet(Tuple <TestSpecificationSheet, FunctionDescriptionSheet> pairSheet,
                                                       ListUIElements elementsAndIndicator, MyLog myLog)
        {
            FunctionSheetParser    functionSheetParser = new FunctionSheetParser();
            List <ClassExpression> classExpressions    = functionSheetParser.parse(pairSheet.Item2, myLog);

            TestSpecSheetParser testSpecSheetParser = new TestSpecSheetParser();

            return(testSpecSheetParser.parse(pairSheet.Item1, elementsAndIndicator, myLog, classExpressions));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="classesExpression"></param>
        /// <param name="projectPath"></param>
        /// <param name="name_space"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns>a list of relative file path</returns>
        private List <string> GenerateClassExpScripts(List <ClassExpression> classesExpression, string projectPath, string name_space,
                                                      ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            List <string> re = new List <string>();

            foreach (ClassExpression classExp in classesExpression)
            {
                re.Add(GenerateClassExpScripts(classExp, projectPath, name_space, listUIElements, mapAliasWithNode, myLog, instanceName));
            }
            return(re);
        }
Пример #7
0
 public static IElement SearchIElement(string name, ListUIElements listUIElements)
 {
     if (listUIElements.Indicator == ListElementsIndicator.AllElements)
     {
         return(listUIElements.Elements.FirstOrDefault(ele => ele.Attributes.Name.Equals(name)));
     }
     foreach (IElement element in listUIElements.Elements)
     {
         IElement temp = DoSearchElementRecursive(name, element);
         if (temp != null)
         {
             return(temp);
         }
     }
     return(null);
 }
        public static string ParamExp2String(string param, ListUIElements listUIElements,
                                             Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName, ScriptType scriptType)
        {
            string tempParamExp = "";

            // Variable_ControlCPUStatus
            if (Regex.IsMatch(param, USER_CODE_WITH_VARIABLE_DECLARE))
            {
                tempParamExp += param;
            }
            // Text Box One.Text
            else
            {
                tempParamExp += Node2ParamExp(param, listUIElements, mapAliasWithNode, myLog, instanceName, scriptType);
            }
            return(tempParamExp);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="listUIElements">only root elements or all elements, depend on indicator attribute</param>
        /// <returns></returns>
        public bool Generate(string filePath, ListUIElements listUIElements)
        {
            // create a temp file
            string tempFilePath = Path.Combine(Path.GetTempPath(), GENERATED_FILE_NAME + "_" + DateTime.Now.ToString("yyMMdd-HHmmss"));

            File.Copy(
                //@"Resources\PictMaster-Template"
                @"D:\Research\projects\GUI-Testing-Automation\TestingApplication\Resources\PictMaster-Template.xls"
                , tempFilePath);

            Application excel = new Application();

            Workbook  workbook  = excel.Workbooks.Open(tempFilePath, ReadOnly: false, Editable: true);
            Worksheet worksheet = workbook.Worksheets.Item[1] as Worksheet;

            if (worksheet == null)
            {
                return(false);
            }

            int rowIdx           = 9;
            int colIdx           = 2;
            int rowConstraintIdx = 66;

            if (listUIElements.Indicator == ListElementsIndicator.AllElements)
            {
                GenerateElements(listUIElements.Elements, ref rowIdx, ref rowConstraintIdx, ref colIdx, worksheet);
            }
            else if (listUIElements.Indicator == ListElementsIndicator.OnlyRootElements)
            {
                GenerateWithElementsRecursive(listUIElements.Elements, ref rowIdx, ref rowConstraintIdx, ref colIdx, worksheet);
            }

            excel.Application.ActiveWorkbook.Save();
            excel.Application.Quit();
            excel.Quit();

            // move temp file to return
            File.Move(tempFilePath, filePath);
            return(true);
        }
        public TestSpecificationScreen parse(TestSpecificationSheet testSpecSheet,
                                             ListUIElements elementsAndIndicator, MyLog myLog, List <ClassExpression> classExpressions)
        {
            NormalSheetParser normalSheetParser = new NormalSheetParser();
            SpecScreen        screen            = normalSheetParser.Parse(testSpecSheet, elementsAndIndicator, myLog);

            if (screen == null)
            {
                return(null);
            }
            TestSpecificationScreen re = new TestSpecificationScreen();

            re.AllUIElements          = elementsAndIndicator;
            re.ListSpecNodes          = screen.ListSpecNodes;
            re.ListValidationUserCode = screen.ListValidationUserCode;
            re.MappingAliasWithNode   = screen.MappingAliasWithNode;
            re.Name             = testSpecSheet.getFeatureName();
            re.Scenarios        = screen.Scenarios;
            re.ClassExpressions = classExpressions;
            return(re);
        }
        /// <summary>
        /// only retrieve MapClassAndFuncsAddition
        /// </summary>
        /// <param name="listUcScriptsExp"></param>
        private List <string> GenerateAdditionScripts(List <UserCodeScriptsExpression> listUcScriptsExp, string projectPath, string name_space,
                                                      ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            Dictionary <string, List <FunctionExpression> > mapClassFunc = new Dictionary <string, List <FunctionExpression> >();

            foreach (var ucScriptsExp in listUcScriptsExp)
            {
                var newMapClassFunc = ucScriptsExp.MapClassAndFuncsAddition;
                foreach (var pair in newMapClassFunc)
                {
                    if (mapClassFunc.ContainsKey(pair.Key))
                    {
                        mapClassFunc[pair.Key].AddRange(pair.Value);
                    }
                    else
                    {
                        mapClassFunc.Add(pair.Key, pair.Value);
                    }
                }
            }
            return(GenerateAdditionScripts(mapClassFunc, projectPath, name_space, listUIElements, mapAliasWithNode, myLog, instanceName));
        }
        /// <summary>
        /// 'GetAttributeValue<object>("Text")' for Ranorex
        /// </summary>
        /// <param name="nodeExp"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mappingAlias"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns></returns>
        public static string Node2ParamExp(string nodeExp, ListUIElements listUIElements, Dictionary <string, string> mappingAlias, MyLog myLog, string instanceName, ScriptType scriptType)
        {
            Tuple <IElement, string> elementAndAttibute = NormalSheetParser.parseNodeAndAttribute(nodeExp, listUIElements, mappingAlias, myLog);

            if (elementAndAttibute == null || elementAndAttibute.Item1 == null)
            {
                myLog.Warn("cannot find node: " + nodeExp);
                return("null");
            }
            if (scriptType == ScriptType.Normal)
            {
                return(GetScriptAccessElement(elementAndAttibute.Item1, instanceName));
            }
            //Ranorex scripts
            string re = getScriptAccessRanorexElement(
                new SpecNode(elementAndAttibute.Item1, elementAndAttibute.Item2, null), instanceName);

            if (elementAndAttibute.Item2 != null && !elementAndAttibute.Item2.Equals(""))
            {
                re += ".GetAttributeValue<object>(\"" + elementAndAttibute.Item2 + "\")";
            }
            return(re);
        }
        /// <summary>
        /// scripts content for a function
        /// </summary>
        /// <param name="functionExpression"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns></returns>
        private string GenerateFunctionExpScripts(FunctionExpression functionExpression, ListUIElements listUIElements,
                                                  Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            string accessibility = functionExpression.GetCorrectAccessibility();
            string summary       = functionExpression.getSummary();
            List <ParameterExpression> @params = functionExpression.getParams();
            string name      = functionExpression.getName();
            string returnDes = functionExpression.getReturnDescription();
            string content   = functionExpression.getContent();

            string re = "";

            if (summary != null)
            {
                re += "/// <summary>" + NEW_LINE;
                string[] listLines = summary.Split('\n');
                foreach (string line in listLines)
                {
                    re += "/// " + line + NEW_LINE;
                }
                re += "/// </summary>";
            }
            var pair = GetParamsScripts(@params, listUIElements, mapAliasWithNode, myLog, instanceName);

            if (pair.Item2 != null && pair.Item2.Count > 0)
            {
                for (int fi = 0; fi < pair.Item2.Count; fi++)
                {
                    string paramName = pair.Item2[fi];
                    string paramDesc = @params[fi].getDescription();
                    if (paramDesc == null)
                    {
                        paramDesc = "";
                    }
                    if (re != "")
                    {
                        re += NEW_LINE;
                    }
                    re += "/// <param name=\"" + paramName + "\">" + paramDesc + "</param>";
                }
            }
            string returnType = functionExpression.GetCorrectReturnType();

            if (returnType != FunctionExpression.VOID)
            {
                if (re != "")
                {
                    re += NEW_LINE;
                }
                re += "/// <returns>" + (returnDes ?? "") + "</returns>";
            }
            if (re != "")
            {
                re += NEW_LINE;
            }
            // Ranorex need to insert annotation
            re += InsertAnnotation();
            re += accessibility + " static " + returnType + " " + name + "(";
            re += pair.Item1;
            re += ")" + NEW_LINE;
            re += "{" + NEW_LINE;
            if (content != null)
            {
                string[] listLines = content.Split('\n');
                foreach (string line in listLines)
                {
                    string line1 = line.Trim().StartsWith("//") ? line.Trim() : "// " + line.Trim();
                    re += line1 + NEW_LINE;
                }
            }
            if (returnType != FunctionExpression.VOID)
            {
                re += "return null;" + NEW_LINE;
            }
            re += "}" + NEW_LINE;
            return(re);
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private List <SpecScreen> DoParse(string filePath, ListUIElements elementsAndIndicator, MyLog myLog)
        {
            string newFilePath = Utils.CreateTempFile(filePath);

            //Create COM Objects. Create a COM object for everything that is referenced
            Excel.Application xlApp      = new Excel.Application();
            Excel.Workbook    xlWorkbook = xlApp.Workbooks.Open(newFilePath);
            //Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];

            List <AbstractSheet> listAbstractSheets = new List <AbstractSheet>();

            for (int fi = 1; fi <= xlWorkbook.Sheets.Count; fi++)
            {
                Excel._Worksheet sheet         = xlWorkbook.Sheets[fi];
                string           name          = sheet.Name;
                AbstractSheet    abstractSheet = null;
                foreach (Tuple <string, string> pairSheetNameRule in SHEET_NAME_TEMPLATE_LIST)
                {
                    Regex           regex   = new Regex(pairSheetNameRule.Item1);
                    MatchCollection matches = regex.Matches(name);
                    if (matches.Count > 0)
                    {
                        string featureName = matches[0].Groups[1].Value;
                        abstractSheet = new TestSpecificationSheet(featureName, sheet);
                    }
                    else
                    {
                        Regex           regex2   = new Regex(pairSheetNameRule.Item2);
                        MatchCollection matches2 = regex2.Matches(name);
                        if (matches2.Count > 0)
                        {
                            string featureName = matches2[0].Groups[1].Value;
                            abstractSheet = new FunctionDescriptionSheet(featureName, sheet);
                        }
                    }
                }
                if (abstractSheet == null)
                {
                    abstractSheet = new NormalSheet(name, sheet);
                }
                listAbstractSheets.Add(abstractSheet);
            }
            List <NormalSheet> normalSheets = new List <NormalSheet>();
            List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> > pairSheets =
                new List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> >();

            foreach (AbstractSheet abstractSheet in listAbstractSheets)
            {
                if (abstractSheet is NormalSheet)
                {
                    normalSheets.Add((NormalSheet)abstractSheet);
                }
                else if (abstractSheet is TestSpecificationSheet)
                {
                    FunctionDescriptionSheet funcDescSheet =
                        findFuncDesc(abstractSheet.getFeatureName(), listAbstractSheets);
                    pairSheets.Add(new Tuple <TestSpecificationSheet, FunctionDescriptionSheet>(
                                       (TestSpecificationSheet)abstractSheet, funcDescSheet));
                }
            }
            List <SpecScreen> screenList = new List <SpecScreen>();

            foreach (Tuple <TestSpecificationSheet, FunctionDescriptionSheet> pairSheet in pairSheets)
            {
                SpecScreen screen = parsePairSheet(pairSheet, elementsAndIndicator, myLog);
                if (screen != null)
                {
                    screenList.Add(screen);
                }
            }
            foreach (NormalSheet normalSheet in normalSheets)
            {
                SpecScreen screen = parseNormalSheet(normalSheet, elementsAndIndicator, myLog);
                if (screen != null)
                {
                    screenList.Add(screen);
                }
            }
            //return screenList;
            //cleanup
            //GC.Collect();
            //GC.WaitForPendingFinalizers();

            //rule of thumb for releasing com objects:
            //  never use two dots, all COM objects must be referenced and released individually
            //  ex: [somthing].[something].[something] is bad

            //close and release
            xlWorkbook.Close(false);
            Marshal.ReleaseComObject(xlWorkbook);

            //quit and release
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);
            return(screenList);
        }
Пример #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private SpecScreen parserOneSheet(Excel._Worksheet sheet,
                                          ListUIElements elementsAndIndicator,
                                          MyLog myLog)
        {
            Excel.Range xlRange     = sheet.UsedRange;
            int         rowCount    = xlRange.Rows.Count;
            int         columnCount = xlRange.Columns.Count;

            SpecScreen screen = new SpecScreen();
            // get mapping alias
            Dictionary <string, string> mapAliasWithNode = getMappingAlias(sheet, rowCount, columnCount);

            screen.MappingAliasWithNode = mapAliasWithNode;

            /**
             * read first row to get all element Nodes
             */
            //Row firstRow = sheet.getRow(ROW_TITLE_TESTCASE);
            string no = getCellValue(sheet, ROW_TITLE_TESTCASE, 1);
            //if (searchElement(no, null, allUIElements) == null && !no.Equals(NO, stringComparison.OrdinalIgnoreCase))
            //{
            //    logWarnings.add("First column must numbered column!");
            //    logger.error("First column must numbered column!");
            //}

            List <SpecNode> listSpecNodes = new List <SpecNode>();
            // <start, end>-s
            List <Tuple <int, int> > listValidationUsercode = new List <Tuple <int, int> >();
            // get each node element
            //int lastColumn = firstRow.getLastCellNum();
            bool link           = false;
            int  startColumnIdx = 2;

            for (int fi = startColumnIdx; fi <= columnCount; fi++)
            {
                string value = getCellValue(sheet, ROW_TITLE_TESTCASE, fi);
                if (value == null || value.Trim().Equals(""))
                {
                    if (checkLastColumn(sheet, fi, rowCount))
                    {
                        columnCount = fi - 1;
                        break;
                    }
                    else
                    {
                        if (listValidationUsercode.Count == 0)
                        {
                            listValidationUsercode.Add(new Tuple <int, int>(fi - 1 - startColumnIdx, fi - startColumnIdx));
                        }
                        else
                        {
                            Tuple <int, int> lastPair = listValidationUsercode[listValidationUsercode.Count - 1];
                            if ((fi - lastPair.Item2 - startColumnIdx) == 1)
                            {
                                listValidationUsercode.RemoveAt(listValidationUsercode.Count - 1);
                                listValidationUsercode.Add(new Tuple <int, int>(lastPair.Item1, fi - startColumnIdx));
                            }
                            else
                            {
                                listValidationUsercode.Add(new Tuple <int, int>(fi - 1 - startColumnIdx, fi - startColumnIdx));
                            }
                        }
                        listSpecNodes.Add(listSpecNodes.Last());
                    }
                }
                else
                {
                    if (Regex.IsMatch(value, AbstractSpecUserAction.LINKS))
                    {
                        columnCount = fi - 1;
                        link        = true;
                        break;
                    }
                    else
                    {
                        SpecNode specNode = parseNode(value, elementsAndIndicator, mapAliasWithNode, myLog);
                        if (specNode == null)
                        {
                            return(null);
                        }
                        listSpecNodes.Add(specNode);
                    }
                }
            }
            screen.Name                   = sheet.Name;
            screen.AllUIElements          = elementsAndIndicator;
            screen.ListSpecNodes          = listSpecNodes;
            screen.ListValidationUserCode = listValidationUsercode;

            /**
             * parseOneFile each scenario
             */
            for (int fi = ROW_TITLE_TESTCASE + 1; fi <= rowCount; fi++)
            {
                //Row row = sheet.getRow(fi);
                bool isRowNotTest = true;
                if (getCellValue(sheet, fi, 1) == null || getCellValue(sheet, fi, 2) == null)
                {
                    rowCount = fi - 1;
                    break;
                }
                SpecScenario scenario = new SpecScenario();
                for (int se = 2; se <= columnCount; se++)
                {
                    Color  color = Color.Empty;
                    string value = getCellValue(sheet, fi, se);

                    /**
                     * check if result indicate 'not_test'
                     */
                    if (listSpecNodes[se - 2].Expression.Equals(AbstractSpecUserAction.RESULT))
                    {
                        if (value.Equals(AbstractSpecUserAction.NOT_TEST))
                        {
                            isRowNotTest = true;
                            break;
                        }
                        else if (value.Equals(AbstractSpecUserAction.TEST) || value.Equals(""))
                        {
                            ;
                        }
                        else
                        {
                            myLog.Warn("[WARNING] Result must be 'Test' or 'Not Test', not " + value +
                                       ", it will be treated as 'Test' by default", logger);
                        }
                    }
                    color = getCellBgColor(sheet, fi, se);
                    if (color.Equals(Color.Empty) || (
                            !color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR1) &&
                            !color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR2)))
                    {
                        isRowNotTest = false;
                    }
                    scenario.UserActionsInString.Add(value);
                    scenario.Colors.Add(color);
                }
                if (isRowNotTest)
                {
                    continue;
                }

                /**
                 * pre-condition
                 */
                string linkExpress   = "";
                string lastCellValue = getCellValue(sheet, fi, columnCount + 1);
                if (link && lastCellValue != null && !lastCellValue.Equals(""))
                {
                    linkExpress = lastCellValue;
                    string[] preConsExp = linkExpress.Split(',');
                    foreach (string preConExp in preConsExp)
                    {
                        scenario.PreConditionsExpression.Add(preConExp.Trim());
                    }
                }
                scenario.Id = fi - ROW_TITLE_TESTCASE;
                //scenario.ScreenName = screen.Name;
                if (screen.Scenarios == null)
                {
                    screen.Scenarios = new List <IScenario>();
                }
                screen.Scenarios.Add(scenario);
            }
            //release com objects to fully kill excel process from running in the background
            Marshal.ReleaseComObject(xlRange);
            Marshal.ReleaseComObject(sheet);
            return(screen);
        }
Пример #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="normalSheet"></param>
 /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
 /// <param name="myLog"></param>
 /// <returns></returns>
 public SpecScreen Parse(AbstractSheet normalSheet, ListUIElements elementsAndIndicator, MyLog myLog)
 {
     return(parserOneSheet(normalSheet.getSheet(), elementsAndIndicator, myLog));
 }
Пример #17
0
        public static Tuple <IElement, string> parseNodeAndAttribute(string expression, ListUIElements elementsAndIndicator,
                                                                     Dictionary <string, string> mappingAlias, MyLog myLog)
        {
            if (mappingAlias != null && mappingAlias.ContainsKey(expression))
            {
                expression = mappingAlias[expression];
            }
            string[] subs = expression.Split('.');
            string   screenName = null; string nodeName = null; string attribute = null;
            IElement element = null;

            //case MainForm
            if (subs.Length == 1)
            {
                nodeName = subs[0];
                element  = searchElement(nodeName, screenName, elementsAndIndicator);
            }
            //case MainForm.Button
            else if (subs.Length == 2)
            {
                screenName = subs[0];
                nodeName   = subs[1];
                element    = searchElement(nodeName, screenName, elementsAndIndicator);
                //case MainForm.Text
                if (element == null)
                {
                    attribute = nodeName;
                    element   = searchElement(screenName, null, elementsAndIndicator);
                }
            }
            //case MainForm.Button.Text and MainForm.DataGridView.Cell(1,1).Text
            else
            {
                screenName = subs[0];
                nodeName   = subs[1];
                attribute  = subs[2];
                for (int i = 3; i < subs.Length; i++)
                {
                    attribute += "." + subs[i];
                }
                element = searchElement(nodeName, screenName, elementsAndIndicator);
            }
            if (element == null)
            {
                string alias = expression.Split('.')[0];
                if (mappingAlias != null && mappingAlias.ContainsKey(alias))
                {
                    return(parseNodeAndAttribute(expression.Replace(alias, mappingAlias[alias]),
                                                 elementsAndIndicator, mappingAlias, myLog));
                }
                else
                {
                    myLog.Warn("Can not find element " + expression, logger);
                    return(null);
                }
            }
            return(new Tuple <IElement, string>(element, attribute));
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="normalSheet"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private SpecScreen parseNormalSheet(NormalSheet normalSheet, ListUIElements elementsAndIndicator, MyLog myLog)
        {
            NormalSheetParser normalSheetParser = new NormalSheetParser();

            return(normalSheetParser.Parse(normalSheet, elementsAndIndicator, myLog));
        }
        /// <summary>
        /// </summary>
        /// <param name="params"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns>{params scripts, list of param's name}</returns>
        private Tuple <string, List <string> > GetParamsScripts(List <ParameterExpression> @params, ListUIElements listUIElements,
                                                                Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            if (@params == null || @params.Count == 0)
            {
                return(new Tuple <string, List <string> >("", null));
            }
            string        re         = "";
            List <string> nameParams = new List <string>();

            for (int fi = 1; fi <= @params.Count; fi++)
            {
                ParameterExpression param = @params[fi - 1];
                if (re != "")
                {
                    re += ", ";
                }
                string varName = "param_" + fi;
                nameParams.Add(varName);
                re += "object " + varName;
            }
            return(new Tuple <string, List <string> >(re, nameParams));
        }